Last active
August 16, 2023 10:45
-
-
Save statgeek/8f90f5c545e01c48e4aaafb82d1a8ae8 to your computer and use it in GitHub Desktop.
SAS - Dictionary Columns - how to filter a variable list to match pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*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