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
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;
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.
if dscode = '30' then flag = 1;
What you are asking sounds simple, I'm not sure if I understand what you are wanting.
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.
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;
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.