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

IF DSCODE IN('01','03','04','05','06','07','08','15','20','21','43','50','51','63','64','65','70')THEN 

       DISCH=1; ELSE

    DISCH=0;

I want to add criteria to this if statement.  I would like the criteria to include something like:  OR if the only dscode by pt id = 30 THEN... (meaning if a patient only has a dscode of 30 in the data, then flag)

is this possible? can someone help me on the syntax?

If there is another way to approach this, I would appreciate any suggestions.  Another option I was thinking about was If last  dscode=30 then flag (by admit date and patient).  

Thank you very much,

Jesse

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I would start with:

DISCH =( DSCODE IN('01','03','04','05','06','07','08','15','20','21','43','50','51','63','64','65','70') );

To assign the basic 0/1 flag.

OR if the only dscode by pt id = 30 THEN...

This looks like you want an except that would be applied because of a single value occurring among multiple records Is that the case? If so you need to determine if that is true for ANY of the records for the value of your Pt_ID variable. Which you are not going to do with a single pass in a data step.

To identify "last" you will need to decide last within an ordered group. If the Patient has multiple records with the same admin date this might work. If the data isn't sorted in the order you need then sort it first.

Proc sort data=have; by AdminDate PatientId;run;  /* This would likely be more useful if there was another variable to specify the order within the patient's record*/

data want;

     set have;

     by AdminDate PatientId;  /* if your data isn't actually sorted but is in a processing sequence then add NOTSORTED */

     DISCH =( DSCODE IN('01','03','04','05','06','07','08','15','20','21','43','50','51','63','64','65','70') );

     if last.PatientId then do;

          if dscode = '30' then <whatever your flag was>;

     end;

run;

View solution in original post

5 REPLIES 5
Reeza
Super User

I think you need to post sample data, since I'm assuming that you're dealing with a scenario where an ID can have multiple records.

Please include expected output as well.

Steelers_In_DC
Barite | Level 11

if dscode = '30' then flag = 1;

What you are asking sounds simple, I'm not sure if I understand what you are wanting.

Jse
Fluorite | Level 6 Jse
Fluorite | Level 6

Sorry for being unclear.

I want the if statement to work as follows:

if the patients dscode is in ('01','03','04','05','06','07','08','15','20','21','43','50','51','63','64','65','70') OR the ONLY dscode the patient has = 30 then disch =1

The other logic I would like to add is: if last dscode by pt id and admit date = 30 then disch = 1

Reeza is correct, there are multiple rows per patient.

The expected output is to have disch = 1 if the dscode falls in the above list OR if the patient only has a ds code of 30 (no other ds codes) OR if the last DSCode by admit date for that patient =30

Thank you for the responses.

ballardw
Super User

I would start with:

DISCH =( DSCODE IN('01','03','04','05','06','07','08','15','20','21','43','50','51','63','64','65','70') );

To assign the basic 0/1 flag.

OR if the only dscode by pt id = 30 THEN...

This looks like you want an except that would be applied because of a single value occurring among multiple records Is that the case? If so you need to determine if that is true for ANY of the records for the value of your Pt_ID variable. Which you are not going to do with a single pass in a data step.

To identify "last" you will need to decide last within an ordered group. If the Patient has multiple records with the same admin date this might work. If the data isn't sorted in the order you need then sort it first.

Proc sort data=have; by AdminDate PatientId;run;  /* This would likely be more useful if there was another variable to specify the order within the patient's record*/

data want;

     set have;

     by AdminDate PatientId;  /* if your data isn't actually sorted but is in a processing sequence then add NOTSORTED */

     DISCH =( DSCODE IN('01','03','04','05','06','07','08','15','20','21','43','50','51','63','64','65','70') );

     if last.PatientId then do;

          if dscode = '30' then <whatever your flag was>;

     end;

run;

Jse
Fluorite | Level 6 Jse
Fluorite | Level 6

Thank you so much for your help.

OR if the only dscode by pt id = 30 THEN...

This looks like you want an except that would be applied because of a single value occurring among multiple records Is that the case? If so you need to determine if that is true for ANY of the records for the value of your Pt_ID variable. Which you are not going to do with a single pass in a data step.

I will work with the LAST statement you gave me.  It should flag ds code 30 if that is a patients only or last ds code.  Thank you again. 

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 957 views
  • 1 like
  • 4 in conversation