SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

macro variable delimiter

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

macro variable delimiter

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


Accepted Solutions
Solution
‎03-14-2018 09:25 AM
PROC Star
Posts: 1,593

Re: macro variable delimiter

Do you wanna quote the macro call:

 

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

 

View solution in original post


All Replies
Solution
‎03-14-2018 09:25 AM
PROC Star
Posts: 1,593

Re: macro variable delimiter

Do you wanna quote the macro call:

 

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

 

Super User
Posts: 6,638

Re: macro variable delimiter

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?

PROC Star
Posts: 1,288

Re: macro variable delimiter

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

Frequent Contributor
Posts: 110

Re: macro variable delimiter

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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