创建宏变量方法
方法1:通过宏函数创建宏变量
%let dsid=%sysfunc(open(sashelp.class));
%let nvars=%sysfunc(attrn(&dsid,nvars));
%let nobs=%sysfunc(attrn(&dsid,nobs));
%let dsid=%sysfunc(close(&dsid));
%put &nvars.;
%put &nobs.;
方法2:通过SQL过程用变量值创建一个宏变量
proc sql noprint;
select distinct sex
into : list_a separated by ' '
from sashelp.class;
quit;
%put &list_a.;
方法3:通过SQL过程用变量值创建多个宏变量
proc sql noprint;
select nvar, nobs
into dictionary.tables
where libname='SASHELP' and memname='CLASS';
/ 注意SASHELP'和CLASS要大写 /
quit;
%put &nvar.;
%put &nobs.;
方法4:通过CONTENTS和SQL过程用变量名创建宏变量
proc contents data=sashelp.class out=con_class;
run;
proc sql noprint;
select name,put(count(name),5,-1)
into :clist separated by ' ',:charct
from con_class
where type=2;
quit;
%put &clist.;
%put &charct.;
方法5:通过SQL过程用变量名创建宏变量列表
proc sql noprint;
select name
into :clist1-:clist999
from dictionary.columns
where libname='SASHELP' and memname='CLASS';
quit;
%put &clist1.;
%put &clist2.;
方法6:通过SQL过程用变量值创建宏变量列表
proc sql noprint;
select count(distinct sex)
into :n
from sashelp.class;
select distinct sex
into :type1 - :type%left(&n)
from sashelp.class;
quit;
%put &n.;
%put &type1.;
方法7:通过DATA步接口子程序CALL SYMPUTX
data null ;
set sashelp.class nobs=obs;
call symputx('m1',obs);
call symput('m2',obs);
stop;
run;
%put &m1.;
%put &m2.;