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

Hi all:

 

I created a macro list by Proc SQL.   However, I found there are space between the ID and could not be recognized in Where statement.  For example, ID is 'DCT00025', 'DEY00056', 'DWR00047', etc.  After the macro, it became ''DCT00025  ', 'DEY00056  ', 'DWR00047 '.   Please advice how to solve this problem.  Thanks.

 

proc sql noprint;
	select ID into : Unmatchlist separated by " ',' " from Unmatch;
quit;
 
%put &Unmatchlist;

data Want;
	set Test (keep = ID SITE DATE);
	where ID in ('&Unmatchlist');
run;

 

Then I got my macro Unmatch list like this:

 

1037 %put &Unmatchlist;

DCT00025  ', '  DEY00056  ', '  DWR00047

 

Which makes them unrecognized in the where statement.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data unmatch;
input id $10.;
cards;
DCT00025
DEY00056
DWR00047
;
proc sql noprint;
	select quote(strip(ID)) into : Unmatchlist  separated by  ','   from Unmatch;
quit;
 
%put &Unmatchlist;


data Want;
	set Test (keep = ID SITE DATE);
	where ID in (&Unmatchlist);
run;
 

View solution in original post

6 REPLIES 6
ybz12003
Rhodochrosite | Level 12

Hi KurtBremser:

 

I think the Q is answered more closed by Novinosrin, although your code is definitely more directly and simple.  

Peter_C
Rhodochrosite | Level 12
Select ID format= $quote100. Into unmatchList separated by ', '
From unmatch

The $quote format applies the trimming
Peter_C
Rhodochrosite | Level 12
I should add the usage of the macro variable needs no quotes:
Where ID in( &unmatchList)
novinosrin
Tourmaline | Level 20
data unmatch;
input id $10.;
cards;
DCT00025
DEY00056
DWR00047
;
proc sql noprint;
	select quote(strip(ID)) into : Unmatchlist  separated by  ','   from Unmatch;
quit;
 
%put &Unmatchlist;


data Want;
	set Test (keep = ID SITE DATE);
	where ID in (&Unmatchlist);
run;
 
Peter_C
Rhodochrosite | Level 12
Storing leading blanks seem unnatural to me, in the SAS environment.
Hence I never think of using STRIP() function.
And I should test whether the $quote format performs STRIP or TRIM in my SQL code above

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 879 views
  • 4 likes
  • 4 in conversation