Hello:
I have the codes list below. I found the codes works fine when I only use either of &classkeeplist or &componentkeeplist. However when I combine these two together and use them in "if statement", it doesn't work. I could see the proc sql generated the two sets of macro list in log. But I don't understand why it didn't work when I use them in data step. Please help, thanks.
proc sql;
select strip(Class) into : classkeeplist separated by '","'
from test
where Class in ('ANTI-INFECTIVES/MISC ANTIBACT',
'ANTIBACTERIALS/MISC B-LACTAM',);
select strip(Component) into : componentkeeplist separated by '","'
from test
where Component in ('NOS- INFLUENZA VACCINE UNKNOWN',
'NOS- NICOTINE PATCH UNKNOWN');
quit;
%put &classkeeplist;
%put &componentkeeplist;
data nosmisc;
set test (where=(max(
prxmatch('/NOS | NOS|-NOS|NOS-|MISC/i',Class),
prxmatch('/NOS | NOS|-NOS|NOS-|MISC/i',Component),
prxmatch('/NOS | NOS|-NOS|NOS-|MISC/i',Product) ) gt 0));
if Class not in ("&classkeeplist") or
Component not in ("&componentkeeplist") then output;
run;
"Doesn't work" tells us exactly NOTHING. Please supply information like the log when an ERROR/WARNING happens, or where the resulting dataset differs from your expectations.
For testing, supply example data in a data step.
Why do it this way in the first place?
data nomisc; set want (where=(class not in ('ANTI-INFECTIVES/MISC ANTIBACT','ANTIBACTERIALS/MISC B-LACTAM') or component not in ('NOS-INFLUENZA...','NOS-...')); if max(prxmatch...,prxmatch...) gt 0; run;
There isn't any need as far as I can tell to take all the sub components into a macro list and then use that, as the first sql will return a list of only
'ANTI-INFECTIVES/MISC ANTIBACT',
'ANTIBACTERIALS/MISC B-LACTAM'
And the second the same on component. Your not actually doing anything ther that isn't a simple where clause??
Very likely: the logic of the final IF statement is wrong. It should use AND instead of OR.
Very likely indeed. Combining negations and OR doesn't build immediately-obvious Boolean clauses.
if ^A | ^B
is the same (but less legible imho) as
if ^(A & B)
Is this really what you want?
Also, you may (or not) want to use the \b expression in your where clause to look for word boundaries.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.