Posts

Showing posts with the label list of variables in a DATA set

How to create a macro variable containing a list of variables in a DATA set

Sometimes it is very handy to have a macro variable contanining the variables names of the dataset. Here are the 2 different ways you can create a macro variable with list of variables names ... *Method1: Using Proc Contents and Proc SQL; proc contents data =sashelp.class out =class; run ; proc sql noprint ; select distinct (name) into :vars separated by " " from class; quit ; %put &vars; *Method2: Using SASHELP tables and Proc SQL; data class; set sashelp.vcolumn(where=(libname= "SASHELP" and memname= "CLASS" )); keep name; run ; proc sql noprint ; select distinct (name) into :vars separated by " " from class; quit; %put &vars;