I have amended the following SAS codes for many times but turned out failed, I want to flag those cases with ever delinquency > 30 days by group, could anyone help to produce the desired results. Thank you.
data Patients;
input PatientID MOB DPD @@;
datalines;
1021 1 10 1042 2 32
1053 1 36 1063 3 13
1053 2 17 1021 3 15
1063 1 11 1042 3 18
1021 2 32 1063 4 43
1042 1 60 1021 4 35
1063 2 12 1053 4 45
1053 3 19 1063 5 73
;
proc sort data=Patients;
by PatientID MOB DPD;
run;
data Result;
set Patients;
by PatientID MOB DPD;
retain ever_flag;
if first.PatientID and DPD > 30 then ever_flag = "Y";
else ever_flag = "N";
run;
Original Results (failed)
Desired Results
Hello,
I think you want this :
data Patients;
input PatientID MOB DPD @@;
datalines;
1021 1 10 1042 2 32
1053 1 36 1063 3 13
1053 2 17 1021 3 15
1063 1 11 1042 3 18
1021 2 32 1063 4 43
1042 1 60 1021 4 35
1063 2 12 1053 4 45
1053 3 19 1063 5 73
;
run;
proc sort data=Patients;
by PatientID MOB DPD;
run;
data Result;
set Patients;
by PatientID MOB DPD;
retain ever_flag;
if first.PatientID then ever_flag='N';
if DPD > 30 then ever_flag = 'Y';
run;
/* end of program */
Koen
Hello,
I think you want this :
data Patients;
input PatientID MOB DPD @@;
datalines;
1021 1 10 1042 2 32
1053 1 36 1063 3 13
1053 2 17 1021 3 15
1063 1 11 1042 3 18
1021 2 32 1063 4 43
1042 1 60 1021 4 35
1063 2 12 1053 4 45
1053 3 19 1063 5 73
;
run;
proc sort data=Patients;
by PatientID MOB DPD;
run;
data Result;
set Patients;
by PatientID MOB DPD;
retain ever_flag;
if first.PatientID then ever_flag='N';
if DPD > 30 then ever_flag = 'Y';
run;
/* end of program */
Koen
if first.PatientID and DPD > 30 then ever_flag = "Y";
else ever_flag = "N";
Whenever first.patientid is false, the whole condition becomes false (because of the AND) and the variable is set to "N".
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.