Last active
August 19, 2021 18:45
-
-
Save statgeek/a3930f0af8ec3cfd0b201867db6ddabc to your computer and use it in GitHub Desktop.
SAS - Create Multiple Macro Variables from a data set
This file contains 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
/*This is an example of how to create multiple macro variables in | |
one SQL step.*/ | |
*note that you do not need to specify the number of items; | |
*SAS will do that portion for you; | |
proc sql noprint; | |
select name into :name1- from sashelp.class; | |
quit; | |
%put &name1; | |
%put &name19.; | |
%put &sqlobs.; | |
**************************************************************************************************; | |
*If you want the number of observations and/or no leading/trailing spaces, TRIMMED removes the extra spaces; | |
**************************************************************************************************; | |
proc sql noprint; | |
select count(distinct name) into :name_count TRIMMED from sashelp.class; | |
quit; | |
%put &name_count; | |
**************************************************************************************************; | |
*Same idea but how to do it via a data ste; | |
*Note if you want global macro variables you can use the 'g' option in CALL SYMPUTX(); | |
**************************************************************************************************; | |
data _null_; | |
set sashelp.class; | |
macro_variable_name = catt('dataStep_name', put(_n_, 2. -l)); | |
call symputx(macro_variable_name, name); | |
run; | |
%put &dataStep_name1; | |
%put &dataStep_name19.; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment