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

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)

kevinmo3_0-1632679907727.png

 

Desired Results 

kevinmo3_0-1632680442691.png

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
sbxkoenk
SAS Super FREQ

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

View solution in original post

4 REPLIES 4
sbxkoenk
SAS Super FREQ

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

kevinmo3
Fluorite | Level 6
Thank you for your assistance. It works.
Kurt_Bremser
Super User
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".

kevinmo3
Fluorite | Level 6
Thank you
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1580 views
  • 3 likes
  • 3 in conversation