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.  

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 530 views
  • 3 likes
  • 5 in conversation