如何格式化proc制表以产生十进制数百万?

时间:2019-08-07 14:17:42

标签: sas format rounding proc tabulate

我的数据采用百万格式,因此我需要将数据制表为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).

有人会熟悉这个问题吗?

1 个答案:

答案 0 :(得分:0)

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

示例:

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;