Hi all,
I came across this question when trying to pull multiple datasets from the same data source. The question is how I can delimit the macro variables when the parameters are defined with multiple numeric values. Below is the example I have. When I tried to plug in the parameters with multiple values like idlist1 and idlist3, the macro cannot take it as the parameters have the same delimiter comma as that between the macro variables "datasetid" and "idlist".
%let idlist1=1111, 3333;
%let idlist2=2222;
%let idlist3=5555,6666,7777;
%macro pull_iddat(datsetid,idlist);
proc sql;
create table want_&datsetid. as
select *
from libdat.datset_a a
inner join libdat.datset_b b on a.joinid = b.joinid
and b.idvar in (&idlist.)
;quit;
%mend;
%pull_iddat(11,&idlist1.);
%pull_iddat(22,&idlist2.);
%pull_iddat(33,&idlist3.);
Can anyone help?
Thanks a lot!
Lizi
Do you wanna quote the macro call:
%pull_iddat(11,%bquote(&idlist1.));
Do you wanna quote the macro call:
%pull_iddat(11,%bquote(&idlist1.));
Ideally, you would create the original variables with a space as a delimiter:
%let idlist3=5555 6666 7777;
Then you would have no problem using &IDLIST3. as a macro parameter. Inside the macro you would have to create a second macro variable. Take 5555 6666 7777 and create a new macro variable with the value:
5555, 6666, 7777
Are your macro programming skills up to the task?
This is an arcane topic called "macro quoting". I suggest you read up on it in the SAS help.
I'm not an expert, so there may be a better way to do it, but I believe this will work:
%let idlist1=%str(1111, 3333);
%let idlist2=%str(2222);
%let idlist3=%str(5555,6666,7777);
Tom
Thank you all! I tried out all the three ways you guys showed, and they all work well. I would definitely look more into "macro quoting" SAS help.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.