BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

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;

 

4 REPLIES 4
Kurt_Bremser
Super User

"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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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??

 

Astounding
PROC Star

Very likely:  the logic of the final IF statement is wrong.  It should use AND instead of OR.

ChrisNZ
Tourmaline | Level 20

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.  

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 4 replies
  • 3373 views
  • 3 likes
  • 5 in conversation