方法1:通過宏函數(shù)創(chuàng)建宏變量
%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過程用變量值創(chuàng)建一個(gè)宏變量
proc sql noprint;
select distinct sex
into : list_a separated by ' '
from sashelp.class;
quit;
%put &list_a.;
方法3:通過SQL過程用變量值創(chuàng)建多個(gè)宏變量
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過程用變量名創(chuàng)建宏變量
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過程用變量名創(chuàng)建宏變量列表
proc sql noprint;
select name
into :clist1-:clist999
from dictionary.columns
where libname='SASHELP' and memname='CLASS';
quit;
%put &clist1.;
%put &clist2.;
方法6:通過SQL過程用變量值創(chuàng)建宏變量列表
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.;