若水烟寒 发表于 2012-11-10 21:57 
I'm sorry I have misunderstood that. But I can't apply the dim() function in the macro. I can't fi ...
You misunderstand the macro loop and data step loop. It is hugely different between them.
Please change the looping as the example below.
2165 data d1;
2166 retain x c v b avcd 0;
2167 run;
NOTE: The data set WORK.D1 has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
2168
2169 %macro name;
2170 data d1;
2171 set d1;
2172 array _allvar_(*) _all_;
2173 do i=1 to dim(_allvar_);
2174 vname=vname(_allvar_(i));
2175 put vname=;
2176 end;
2177 run;
2178 %mend name;
2179 %name;
vname=x
vname=c
vname=v
vname=b
vname=avcd
NOTE: There were 1 observations read from the data set WORK.D1.
NOTE: The data set WORK.D1 has 1 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time 0.06 seconds
cpu time 0.01 seconds