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.
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;
Do it in one SQL:
proc sql;
create table want as
select id, site, date
from test
where id in (select id from unmatch);
quit;
Hi KurtBremser:
I think the Q is answered more closed by Novinosrin, although your code is definitely more directly and simple.
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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.