section 1) Creating a flag for each new instance of a rash on a different body part Instead of doing a loop I would approach this with a first. proc sort data=have; by ID Body_Part Rash_Date; run; data want; set have; by ID Body_Part Rash_Date; if first.Body_Part then New_Body_Part="Y"; run; Section 2) creating flag variable Repeat_Part when the hours difference between Rash date time and last drug adminstration date time for the same body Part if it is more than 50 hours then Repeat Part = "Y". There can be multiple rashes at different body Parts. For this section you would need the variable for last drug administration date-time and merge it with original dataset. Then you can derive the number of hours between rash date-time and last drug administration date-time. I would approach this with a macro for each body part. %macro repeat_fl(body_part=); data tmp; set have; if body_part="&body_part."; if n(rash_date, drug_admin_date)=2 then hr_diff=intck('hour', rash_date, durg_admin_date); if hr_diff>50 then repeat_part="Y"; run; %mend repeat_fl;
... View more