/* rst.sas Daniel Brockman 20070429 Returns list of vars in dataset */ /* * %rst(dsn) assumes the value of a variable containing * a list of the variable names in data set &dsn . * * Example: * * %let rstx = %rst(mydataset); * %put List of Variables in mydataset: &rstx ; * * Shamelessly plagiarized from * http://support.sas.com/ctx/samples/index.jsp?sid=597 */ /*---------------------------------------------*/ %macro rst(dsn); %local rstx dsid cnt rc ; %let rstx=; /* Open the data set */ %let dsid=%sysfunc(open(&dsn)); /* The variable CNT will contain the number of variables that are in the */ /* data set that is passed in. */ %let cnt=%sysfunc(attrn(&dsid,nvars)); /* Create a macro variable that contains all dataset variables */ %do i = 1 %to &cnt; %let rstx=&rstx %sysfunc(varname(&dsid,&i)); %end; /* Close the data set */ %let rc=%sysfunc(close(&dsid)); &rstx ; %mend rst; /*---------------------------------------------*/