/* listovars Daniel Brockman 20120119 Put list of ds vars in Macro var. */ /* options ls=80 mprint symbolgen mlogic ; /* test */ %macro listovars(dsn) ; /* listovars uses proc contents to read the names of vars from a dataset. /* listovars puts the list of names in global macro variable glist. /* /* dsn = dataset from which to read variable names. /* /* Example: /* %global glist ; /* %listovars(mylib.mydataset) ; /* %let mylist = &glist ; /* */ %global glist ; proc contents data=&dsn out=listovars_a noprint ; run; data _NULL_ ; length nc $8. ; /* character rep of number */ set listovars_a ; nc=left(put(_N_,8.)) ; call symput('L'||nc,NAME) ; /* create &L1 &L2 &L3, etc. */ call symput('NNN',nc) ; /* number of items */ run; %let glist= ; /* init */ %let ii=1 ; %do %while ( &ii le &NNN ) ; %let glist=&glist &&L&ii ; /* compose list */ %let ii=%eval(&ii+1) ; %end ; %mend listovars ; /* ------------------------------------------------------------------- */ /* Test data bozo ; format bravo $18. ; input alpha bravo $ charlie ; cards; 1 walter 5 2 yves 8 3 zelda 9 ; proc print data=bozo; run; %listovars(bozo) ; %let YAMHEAD=&glist ; %put YAMHEAD: &YAMHEAD ; /* End Test */ /* ------------------------------------------------------------------- */