*filename pgm '/mscdc/sasmacro/genvarc.sas'; /******************************************************************** * NAME: genvarc SYSTEM: MSCDC PGMR: BLODGETT * * FUNCTION: generate a SAS source code file with SAS variable names * * taken from specified input dataset. Can be used to generate these * * cannibalizable modules that have all the names, optionally with * * labels as comments. * * Sample output can look like either: * * var1 var2 var3 areaname latitude longitud ... * * --or-- (with slashes turned backward for obvious reasons): * * var1 \* this is variable 1 and its label *\ * * var2 \* and this is var2 *\ * * var3 \* and so forth. include this code and use *\ * * NOTES: * ********************************************************************/ %GLOBAL REVDATE; %LET REVDATE=25SEP95; *<----DATE OF LAST REVISION; /********************************************************************/ /* BEGIN MACRO DEFINITION */ /********************************************************************/ %MACRO genvarc ( setin=_last_, /* input dataset for which we are to retrieve vars */ fileout=temp.sas, /* the file statement used to write is: file &fileout */ labels=0, /* labels=1 if you want the label of each var written as a comment after its name, one variable per line */ stream=1, /* says to stream output, 8 vars per line. cannot be used if labels=1 is specified (if labels=1 then stream=0)*/ orderby=varnum, /* variables will be sorted by this variable (the relative position of the variable in the set. name is the other viable value. */ debug=0); /* END */ %PUT %STR( ); %PUT ***************************************************************; %put * genvarc macro Rev &revdate begin execution *; %put * Missouri State Census Data Center *; %PUT ***************************************************************; %PUT %STR( ); %if &labels %then %let stream=0; proc contents data=&setin noprint out=_genvarc(keep=varnum name label); run; %if &orderby ne name %then %do; proc sort data=_genvarc; by &orderby; run; %end; data _null_; set _genvarc end=last; %if %index(%quote(&fileout),%str(/)) or %index(%quote(&fileout),%str(.)) %then %str(file "&fileout"; ); %else %str(file &fileout; ); %if &labels %then %do; put @2 name $8. ' /* ' label '*/' ; %end; %else %do; %if &stream %then %do; __nv +1; drop __nv; put name $9. @; if __nv=8 then do; put; __nv=0; end; %end; %else %str(put @2 name; ); %end; if last then do; file log; put '*** ' _n_ " variables written to &fileout.*** "; end; run; %MEND genvarc;