BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lizzy28
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Do you wanna quote the macro call:

 

%pull_iddat(11,%bquote(&idlist1.));

 

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

Do you wanna quote the macro call:

 

%pull_iddat(11,%bquote(&idlist1.));

 

Astounding
PROC Star

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?

TomKari
Onyx | Level 15

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

lizzy28
Quartz | Level 8

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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 4 replies
  • 1919 views
  • 3 likes
  • 4 in conversation