1 min read

List Processing With SAS (2): List Creating II

%range is a genetic list creator. To apply data driven programming technique, we need to fetch metadata from source data dynamically, for example, to get all variables from a input dataset.

You can easily make it by

1. PROC SQL, from a SAS dictionary table, or macro variable by SELECT INTO; or

2. Proc Contents; or

3. even a smart data step with RESOLVE function and with CALL SYMPUT, like

%let namelist=;
data _null_;
    set sashelp.class;
    call symput('namelist', trim(resolve('&namelist'))||' '||trim(name));
%put &namelist;


In my repository, there is a elegant function-like macro where SAS file processing functions like open(), close() are used, %getVar. Below follows examples to fetch variables from a dataset, based on variable type, numeric or character:

filename list url “https://raw.github.com/Jiangtang/SAS_ListProcessing/master/_ListProcessing”;

%inc list;

%put %getVar(%str(sashelp.class));

%put %getVar(%str(sashelp.class),n);

%put %getVar(%str(sashelp.class),C);


Name Sex Age Height Weight

    Age Height Weight </span>

    Name Sex


    <span style="font-size: xx-small;">Another example to list all the elements from a directory using </span><a href="https://github.com/Jiangtang/SAS_ListProcessing/blob/master/dir.sas"><span style="font-size: xx-small;">%dir</span></a><span style="font-size: xx-small;"> by </span><a href="http://www.datasavantconsulting.com/roland/"><span style="font-size: xx-small;">Roland Rashleigh-Berry</span></a><span style="font-size: xx-small;">:</span>

      <span style="font-family: 'Courier New'; font-size: xx-small;">%put %dir(d:\test);</span>

    <span style="font-size: xx-small;">For more, check out the List Creating part of the portal:</span>

    <a href="https://github.com/Jiangtang/SAS_ListProcessing"><span style="font-size: xx-small;">https://github.com/Jiangtang/SAS_ListProcessing</span></a>