fxf258 发表于 2012-3-25 11:02 
谢谢各位的赐教,出差几天未能查看!
还有些疑问,想请教:如果我写的宏程序格式如下,怎么编写呢?
%m ...
I think I got what you need.
You have a list of variables that is available at running time. It is stored in mavro variable varname.
for example varname contains a1 a2 a3 ... and you want to define a sum variable as
sumvar=sum(a1,a2,a3,....);
Here is a simple macro which will do it at running time.
For some macro string manipulating you can read my post
'shape' a macro variable into a desired look
https://bbs.pinggu.org/thread-699918-1-1.html
***********************************************************
data t1;
retain an 1 bnj 2 avf 3 ah 4 a n b c 1;
output;
run;
%macro sum(dsin, dsout, varlist);
%let sumvar=;
%let n= %eval(%sysfunc(countc(%cmpres(&varlist),%str( )))+ (%length(&varlist)>0) );
%do i = 1 %to &n;
%let cur_var=%scan(&varlist,&i);
%if &i=1 %then %let sumvar=&sumvar &cur_var;
%else %let sumvar=&sumvar , &cur_var;
%end;
data &dsout;
set &dsin;
sumvar=sum(&sumvar);
run;
%mend;
option mprint;
%sum(t1, t1out, an bnj avf);
proc print;run;
%sum(t1, t1out, a n b c);
proc print;run;
%let v=an avf a c;
%sum(t1, t1out, &v);
proc print;run;