|
title;
/*获得数据集SASHELP.CLASS中的变量名的名字以及类型,1=数值型 2=字符型*/
proc contents data=sashelp.class out=stuff(keep=name type) noprint;
run;
data temp;
set stuff;
length sumname $14.;
sumname=cats(name,'_total'); /*给每一个变量名字添加后缀_total,以示区别初始变量的名字*/
run;
/* look at new name */
proc print data=temp;
title 'temp';
run;
title;
/* create macro var with list of numeric variable names */
proc sql;
select (sumname)
into :outname separated by ' ' /*将添加后缀和原始变量的名字一次赋值给宏变量*/
from temp
where type = 1;
select (name)
into :inname separated by ' '
from temp
where type = 1;
quit;
proc means data=sashelp.class;
var &inname;
output out=mymeans sum= &outname; /*计算每一个变量的汇总*/
run;
proc print data=mymeans;
title 'mymeans';
run;
值得学习:
1.CONTENTS使用,获得变量,变量的类型
2.SQL中的宏使用
|