首页 > 解决方案 > 如何格式化 proc 表格以产生十进制数百万?

问题描述

我的数据格式为百万,我需要在 SAS 中将我的数据以十进制数百万制表。

我的数据包含数百万美元的租金,即 1,260,678.21,我希望将其制成十进制数百万,即“1.3”。

我试图创建自己的函数来划分如下:

           /***/
* create a function to round 
*;

      proc fcmp outlib=work.function.sample;
      function round1000x(value);
      return(round(value/1000000,1));
      endsub; 
      run; 

  *
  * make function available
  *;
  options cmplib=work.func;

   *
   * create a format that uses the function
   *;
   proc format; 
     value round1000x.;
   run; 


 /*use this format in a proc tabulate statement*/

 proc tabulate data=my_data format=round1000x.;
var rent_cost;
table rent_cost;
  run;

但是我收到错误:

ERROR: The format ROUND1000X has a label that defines another format to be 
 loaded (named ROUND1000X), but this format could not be 
   successfully loaded (possibly for the same reason).

有人会熟悉这个问题吗?

标签: sasformatroundingproctabulate

解决方案


您可以创建一个视图,将值缩放到所需的大小并将其制成表格。

例子:

data have;
  do street = 1 to 50;
    rent = 7e5 + street * 1e5;
    output;
  end;
run;

data forTabulate / view=forTabulate;
  set have;
  rentM = round (rent / 1e6, 0.01);
run;

proc tabulate data=forTabulate;
  class street;
  var rentM;
  table street, rentM*sum='($M)'*f=5.2;
run;

推荐阅读