Skip to content

Instantly share code, notes, and snippets.

@statgeek
Last active August 16, 2023 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save statgeek/8f90f5c545e01c48e4aaafb82d1a8ae8 to your computer and use it in GitHub Desktop.
Save statgeek/8f90f5c545e01c48e4aaafb82d1a8ae8 to your computer and use it in GitHub Desktop.
SAS - Dictionary Columns - how to filter a variable list to match pattern
*How to selectively filter your list of variables in a SAS data set with a pattern but not one that uses SAS variable shortcuts;
options mprint symbolgen;
%macro select(lib =, ds_in=, pattern=, ds_out=);
proc sql noprint;
select nliteral(name) into :var_list separated by ' '
from dictionary.columns
where libname = upcase("&lib")
and memname = upcase("&ds_in")
and find(name, "&pattern.", 'it')>0;
quit;
data &ds_out;
set &lib..&ds_in.;
keep &var_list.;
run;
%mend;
%select(lib=sashelp, ds_in=cars, pattern=mpg, ds_out=demo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment