%macro smryvars(setin=_last_, /* Utility macro to invoke proc summary (equiv of proc means) specifying parms for generating a series of univariable stats for a specified list of variables with a specified list of class vars. Output is a data set with 1 obs per class category / variable. The variables on the output set are <&classvars>, VarName VarLabel <&stats> , where we reference the values of the 2 parm lists. John Blodgett, OSEDA, 2-16-09. */ setout=, vars=, stats=, classvars=, report=1 /* set to 0 to NOT generate a report showing results */ ); %let _nvars=%lenlst(&vars); %let _nstats=%lenlst(&stats); ods output close; *<---just in case it may have been left open---; ods listing close; ods output summary=ods_smryvars; proc means data=&setin &stats; var &vars ; class &classvars; output out=_null_ %do j=1 %to &_nstats; %let stat=%scan(&stats,&j); %str( &stat.= ) %end; /autoname autolabel; run; ods output close; ods listing; data &setout; set ods_smryvars; length VarName $32 VarLabel $64 &stats 8; %do i=1 %to &_nvars; %let var=%scan(&vars,&i); VarName="&var"; VarLabel=label_&var; %do j=1 %to &_nstats; %let stat=%scan(&stats,&j); &stat = &var._&stat; %end; keep &classvars VarName VarLabel &stats; ***label varname='Name' varlabel='Label'; output; %end; run; %if &report %then %do; proc print data=&setout ; by &classvars; id &classvars; var VarName VarLabel &stats; title2 "Listing of &setout.: Statistics Based on &setin"; run; %end; %mend smryvars; /* ===================Test run============================================= options mprint; %smryvars(setin=popests.datasets,setout=sasuser.smryvars, vars=nobs nvars kbytes,stats=n nmiss sum median,classvars=libname) run; ============================End Test======================================= */