I have the following example data set:
data test;
test = "A123"; output;
test = "B123"; output;
run;
I would like to to assign the values A123 and B123 into a macro so that the result would be the same as :
%let readin=("A123" "B123")
Then I would use &readin. in data step's where statement.
One common way to read a list of values from a dataset variable into a macro variable is to use PROC SQL:
proc sql noprint ;
select quote(test) into :readin separated by " "
from test
;
quit ;
%put &readin ;
This will return:
"A123" "B123"
If you want to include the parentheses in the value, I think the easiest way is to add them with a %LET statement after the PROC SQL step:
proc sql noprint ;
select quote(test) into :readin separated by " "
from test
;
quit ;
%let readin=(&readin) ;
%put &readin ;
One common way to read a list of values from a dataset variable into a macro variable is to use PROC SQL:
proc sql noprint ;
select quote(test) into :readin separated by " "
from test
;
quit ;
%put &readin ;
This will return:
"A123" "B123"
If you want to include the parentheses in the value, I think the easiest way is to add them with a %LET statement after the PROC SQL step:
proc sql noprint ;
select quote(test) into :readin separated by " "
from test
;
quit ;
%let readin=(&readin) ;
%put &readin ;
Data, like these two text values, is much more easily handled in a SAS data set. It is much less easily handled in a macro. While there are reasons why a macro may be the best choice, those reasons are rare. We could give you better advice if we knew what you are planning to do with these character strings. Please tell us what you are going to do next with these character strings?
A minor comment about terminology: you are not creating a macro, you care creating a macro variable. Macro variables are not the same as macros.
I am using it to load in only a subset of a huge data set. So in the data step I restrict using where=(variable in (@readin.))
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.