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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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. 

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

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
BTAinRVA
Quartz | Level 8

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

Reeza
Super User

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. 

Astounding
PROC Star

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. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 3967 views
  • 1 like
  • 4 in conversation