/* mkvarlist.sas Daniel Brockman Make list of var names in a data set. */ /* --------------------------------------------------------- */ %macro mkvarlist(inp) ; /* * %mkvarlist returns, in global variable greturn, * a list of the names of the variables in input data set &inp . * Example: * %global greturn ; * %mkvarlist(mylib.mydataset) ; * %let vlist = &greturn ; */ /* make names of temporary data sets */ /* This ijk stuff extracts the 1st 4 chars of the libname */ %let k = %scan(&inp,1) ; %let i = %length(&k) ; %let j = %eval(&i-3) ; %if ( &i < 1 ) %then %let k = ; %else %if ( &i > 4 ) %then %let k = %substr(&k,&j,4) ; %else %let k = %substr(&k,1,&i) ; /* This ijk stuff extracts the last 4 chars of the dataset name */ %let L = %scan(&inp,2) ; %let i = %length(&L) ; %let j = %eval(&i-3) ; %if ( &i < 1 ) %then %let L = ; %else %if ( &i > 4 ) %then %let L = %substr(&L,&j,4) ; %else %let L = %substr(&L,1,&i) ; %let c3po = &k.&L._c3p ; /* temporary data set for proc contents output */ ; /* put the names of the input set variables in data set &c3po ; */ proc contents data=&inp noprint varnum out=&c3po ; run; /* extract names of variables into macro var mkvlist */ data _NULL_ ; set &c3po; length ob2kinob $ 8192; /* I hope this is long enough */ retain ob2kinob; if (_N_=1) then ob2kinob=trim(name); else ob2kinob= trim(ob2kinob) || ' ' || trim(name) ; call symput('mkvlist',trim(ob2kinob)); run; /* assume the value of the list of variables */ %let greturn = &mkvlist. ;; /* this works */ /* * &mkvlist. ;; this doesn' t work */ %mend mkvarlist; /* --------------------------------------------------------- */ /* --------------------------------------------------------- */ /* --------------------------------------------------------- */ /* --------------------------------------------------------- */ ;