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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 3181 views
  • 1 like
  • 4 in conversation