How to get the data set variable list into a macro variable

Sometimes when you have a huge SAS dataset and would like to list or print the variable names in the dataset, it is better to store the list of variable names into a macro variable first and then you can use this macro variable to either print or select the specific columns which you wanted.

There are multiple ways to do this, for example using PROC CONTENTS or a better way below:

proc sql noprint; 
 select distinct name 
 into : varlist separated by ' '
 from dictionary.columns
 where upcase(libname)='WORK' and 
       upcase(memname)='Your-data-set-name';
quit;
Posted in SAS Programming Tips.

Leave a Reply

Your email address will not be published. Required fields are marked *