BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

How do I exclude both EM codes and OP procedures from my data? Are the operators correct?

 

data HospOPDept;
set OUTPAT;
real_date=input(eventdate,YYMMDD10.);
/*format real_date date9.;*/
format real_date yyq6.; /*year-qtr*/
where rptGrouper not in ("OP Procedures")
or (cpt not between '99201' and '99215')
or (cpt not between '99241' and '99245')
or (cpt not between '99381' and '99397')
or (cpt not between '99354' and '99355')
or (cpt not between '99401' and '99412')
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions

Here's what I did and it worked (I created a macro for the codes instead of listing them out and did a "where also" statement to exclude those codes in addition to excluding OP Procedures):

 

data HospOPDept;
set OUTPAT;
real_date=input(eventdate,YYMMDD10.);
/*format real_date date9.;*/
format real_date yyq6.; /*year-qtr*/
where rptGrouper not in ("OP Procedures");
where also cpt not in &EMCODES;
run;

View solution in original post

5 REPLIES 5
Reeza
Super User

Guessing:

 

where rptGrouper not in ("OP Procedures")
AND ((cpt not between '99201' and '99215')
or (cpt not between '99241' and '99245')
or (cpt not between '99381' and '99397')
or (cpt not between '99354' and '99355')
or (cpt not between '99401' and '99412'))
;

I used an "OR" operator but it's not excluding those codes or OP procedures...

SASKiwi
PROC Star

Try ANDs:

where rptGrouper not in ("OP Procedures")
and (cpt not between '99201' and '99215')
and (cpt not between '99241' and '99245')
and (cpt not between '99381' and '99397')
and (cpt not between '99354' and '99355')
and (cpt not between '99401' and '99412')
;
ballardw
Super User

It might be a good idea to provide some example data, the basic rules (not code when you don't have code that works) and an example of the output for the example data.

It may be that you need more parentheses for grouping related concepts.

 

https://brilliant.org/wiki/de-morgans-laws/  may help a bit to work out some details of OR , AND combinations of logic.

 

This "trick" of converting your values to numeric, assuming all of the values you need to test follow the 5 digit examples, may help simplify the code:

data have;
   input x $;
datalines;
99123
99124
99125 
99127
99234
99235
99236
99237
;

data example;
   set have;
   where input(x,f5.) not in (99123:99125 99234:99236);
run;

The IN operator will accept numeric ranges, indicated by the : between two integers to select integer values and might considerably reduce the amount of code needed. The above code excludes values and is what I think could replace

(cpt not between '99123' and '99125')
and (cpt not between '99234' and '99236')

Personally I will go out my way to do any comparisons with text values and ranges as they so seldom work nicely. If every single value has the exact same number of characters then maybe.

Here's what I did and it worked (I created a macro for the codes instead of listing them out and did a "where also" statement to exclude those codes in addition to excluding OP Procedures):

 

data HospOPDept;
set OUTPAT;
real_date=input(eventdate,YYMMDD10.);
/*format real_date date9.;*/
format real_date yyq6.; /*year-qtr*/
where rptGrouper not in ("OP Procedures");
where also cpt not in &EMCODES;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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