0

i want to Calculate how many variable and out put in log

i want use do loop

this is my Program

%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)

thanks

4

1 回答 1

0

我同意 Dirk 的观点,这可能不是一个好主意,但它相当微不足道。这有一些很好的理由;主要是使用具有未知参数计数的参数列表。如果您想查看更彻底的用法,请查找通常需要此功能的 SYSPARM ( http://support.sas.com/documentation/cdl/en/mcrollref/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)
于 2013-04-29T14:28:14.797 回答