List Processing With SAS (2): List Creating II

This post was kindly contributed by From a Logical Point of View » SAS - go there to comment and to read the full post.

%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));
run;
%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);

Outputs:

Name Sex Age Height Weight

Age Height Weight

Name Sex

 

Another example to list all the elements from a directory using %dir by Roland Rashleigh-Berry:

%put %dir(d:\test);

For more, check out the List Creating part of the portal:

https://github.com/Jiangtang/SAS_ListProcessing

This post was kindly contributed by From a Logical Point of View » SAS - go there to comment and to read the full post.