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

Hello

I am using proc sql with into statement to create SAS Macro Varaible.

In this example I create a  Macro Varaible called nameP that should recieve value   "Peter","Paul"

What is the correct way to get it?

In the code that I wrote I get value Peter,Paul  and then there is an error 

******INTO Statement in PROC SQL to Create Macro Variables******;
 
data RawData;
length name $10;
input name $;
datalines;
Peter
John
Paul
David
;
run;

/*Solution with error*/
proc sql noprint;
select name
into :namesP separated by ','
from RawData
where substr(name,1,1) = 'P'
;
quit;
%put &namesP;/*Peter,Paul*/

data Outcome;
set RawData;
where name IN (&namesP.);
run;


/*Correct solution*/
%let names="Peter","Paul";
data Outcome;
set RawData;
where name IN (&names.);
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

If you need quotes, you have to set them:

data RawData;
length name $10;
input name $;
datalines;
Peter
John
Paul
David
;
run;

proc sql noprint;
select quote(trim(name))
into :namesP separated by ','
from RawData
where substr(name,1,1) = 'P'
;
quit;

%put &namesP;

Log excerpt:

46         %put &namesP;
"Peter","Paul"

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

If you need quotes, you have to set them:

data RawData;
length name $10;
input name $;
datalines;
Peter
John
Paul
David
;
run;

proc sql noprint;
select quote(trim(name))
into :namesP separated by ','
from RawData
where substr(name,1,1) = 'P'
;
quit;

%put &namesP;

Log excerpt:

46         %put &namesP;
"Peter","Paul"

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 386 views
  • 1 like
  • 2 in conversation