01-05-2018 08:49 AM
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.
select strip(Class) into : classkeeplist separated by '","'
where Class in ('ANTI-INFECTIVES/MISC ANTIBACT',
select strip(Component) into : componentkeeplist separated by '","'
where Component in ('NOS- INFLUENZA VACCINE UNKNOWN',
'NOS- NICOTINE PATCH UNKNOWN');
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;
01-05-2018 09:00 AM
"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.
01-05-2018 09:04 AM
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
And the second the same on component. Your not actually doing anything ther that isn't a simple where clause??
01-07-2018 11:38 PM
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.