2013-04-28 95 views
0

来计算投入多少变量,并进行日志计算我需要多少变量

我想用做循环

这是我的计划

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

谢谢

+0

你为什么要做这个,你输入3个变量所以3应该出来了吧? – 2013-04-29 12:40:52

回答

0

我同意德克这可能不是一个好主意,但它是相当微不足道的。这有一些很好的理由。主要是使用参数数量未知的参数列表。如果你想看到更全面的用法,查找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)