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;
Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!
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.