计算有多少变量

  • 本文关键字:变量 多少 计算 sas
  • 更新时间 :
  • 英文 :


我想计算在日志中有多少变量和输出

i want use do loop

这是我的程序

%PUT _USER_;

OPTIONS MPRINT;

%MACRO varnum(a);
data d;
array a &a. ;
%do i=1 %to %str(dim(a)-1);
%put there are &i variables;
%end;
run;
%MEND;
%varnum(age  income   educ)

谢谢

我同意Dirk的观点,这可能不是一个好主意,但它相当微不足道。这有一些很好的理由;首先,使用参数数量未知的参数列表。如果您想查看更全面的用法,请查找SYSPARM (http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543608.htm),它通常需要这种操作(并且可能是处理参数数量未知问题的正确方法,尽管这实际上没有任何不同)。

%MACRO varnum(a);
data d;
array a &a. ;
%do i=1 %to %sysfunc(countc(%sysfunc(compbl(&a)),%str( )))+1; 
*First COMPBL (remove extra spaces) to ensure one space between parameters;
*Then count the number of spaces between parameters, and add one since (1 2 3) has 2 spaces;
%put there are &i variables;
%end;
run;
%MEND;
%varnum(age  income   educ)

最新更新