I have a table with columns for person_id, Encounter_Date, Diagnosis1-10, and DxCode. How can i flag the first DxCode that starts with "S06" for each separate person_id and Encounter_Date?
Thanks,
Brian
Here's what I think you are looking for:
proc sort data=have; by person_id Encounter_Date; run;
data want;
set have;
by person_id Encounter_Date;
if first.Encounter_Date then do;
flag=0;
S06_found=0;
end;
retain flag S06_found;
if DxCode =: 'S06' then do;
S06_found + 1;
if S06_found=1 then flag=1;
else flag=0;
end;
else flag=0;
drop S06_found;
run;
It gets a little tricky because there can be multiple, different Dx Codes that begin with S06 on the same date.
If you don't mind sorting your data:
proc sort data=have; by person_id Encounter_Date DxCode; run;
data want;
set have;
by person_id Encounter_Date DxCode;
flag = first.DxCode and DxCode =: "S06";
run;
PG,
Thanks for the reply. I was able to get it to work with some minor tweaks (needed because i didn't explain my problem well enough).
Brian
Starts with makes it a bit more difficult.
I think you'll have to create an array of the diags and loop over them unfortunately. If it was full code I would use WHICHC Function.
Here's what I think you are looking for:
proc sort data=have; by person_id Encounter_Date; run;
data want;
set have;
by person_id Encounter_Date;
if first.Encounter_Date then do;
flag=0;
S06_found=0;
end;
retain flag S06_found;
if DxCode =: 'S06' then do;
S06_found + 1;
if S06_found=1 then flag=1;
else flag=0;
end;
else flag=0;
drop S06_found;
run;
It gets a little tricky because there can be multiple, different Dx Codes that begin with S06 on the same date.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: