BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CathyVI
Pyrite | Level 9

Hello,

I got stuck with this coding and would appreciate any help.

I am interested in find the initial/first ever cancer diagnosis (Ischemic Stroke or Hemorrhagic Stroke), the date of initial diagnosis. Then I want to find if there a recurrent dx of ischemic or Hemorrhagic Stroke and create a label for it as recurrent if it occurred after the initial/first cancer diagnosis.

For Atrial Fibrillation (AFIB), I want to create a label for each ICD code and label the encounter as pre/post initial stroke depending on the encounter date and initial stroke date.

I want to pull data for seizure diagnosis and create a label for each ICD code and label the encounter as “post” initial stroke.

Ischemic Stroke ICD 9 codes: 433, 434, 436, I63, I693, G459

Hemorrhagic Stroke ICD 9 codes: 430, 431, 4320, 4321, 4329, I60, I61, I62

Recurrent Ischemic Stroke ICD 9 codes: 435, 436, 433, 434, I60 – I64

AFIB ICD9/10: 42731, I480, I481, I482, I489

Seizure ICD 9/10: 345, 78039, 345, 6494, G40

 

data have;
infile datalines dsd;
informat ID diag_dt dx1 dx2 dx3 dx4;
input ID $ 1-7 @8 diag_dt :date9. dx1 $ 18-23 dx2 $ 24-29 dx3 $ 30-35;
informat diag_dt date9.;
format diag_dt date9.;
datalines;
0036059 02AUG2023 G459 I4729 I10
0036059 23JUN2023 G459 R29810 I6782
0036059 28JUN2023 Z8673 G459
0036059 14SEP2023 G459 Z8673
0068059 19OCT2009 436
0095408 04AUG2023 A419 I253 K625
0095408 26JUL2021 G459
0095408 22APR2024 I6389 Q2112
0114279 10JUL2003 430 7843 7820
0114279 11JUL2003 74781 431
0114279 16JUL2003 431 74781
0114279 10JUL2003 431 7820
0114279 17JUL2003 4329
0126660 04OCT2006 30924 4321 30742
0126660 18SEP2006 4321
0126660 25SEP2006 4321
0126660 16OCT2006 V679 8509 4321
0204855 09SEP2009 436 78609 V681
0324626 20JUN2002 436 7843 34211
0324626 21JUN2002 436
0324626 01AUG2002 436
0346276 30NOV2009 431 5849 4010
0346276 02DEC2009 431
0222626 01AUG2002 433
0222626 30NOV2009 433 5849 4010
0222626 02DEC2009 G40 6494
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Here is one way that works with the example data to identify first/subsequent by topic of interest

proc sort data=have;
   by id diag_dt dx1-dx3;
run;
/* the sort and transpose by multiple variables is because of 
/* multiple rows of data with the same date*/
/* and need to filter the output to get one ICD value per observation*/
proc transpose data=have out=trans ( where=(not missing(ICD1)) drop=_name_ dx1-dx3)
   prefix=ICD;
   by id diag_dt dx1-dx3;
   var dx1-dx3;
run;

proc format library=work;
  value $icd 
  '433', '434', '436', 'I63', 'I693', 'G459' = "Ischemic Stroke"
  '430', '431', '4320', '4321', '4329', 'I60', 'I61', 'I62' = "Hemorrhagic Stroke"
  '42731', 'I480', 'I481', 'I482', 'I489' = "AFIB"
  '345', '78039', '6494', 'G40'= "Seizure"
  other='N/A'
  ;
run;

data helpful;
   set trans;
   ICD_text = put(icd1,$icd.);
run;

proc sort data=helpful;
   by id ICD_text  diag_dt;
run;

data need;
   set helpful;
   by id ICD_text  diag_dt;
   if first.ICD_text then do;
      select (Icd_text);
         when ("Ischemic Stroke") First_IS=1;
         when ("Hemorrhagic Stroke") First_HS=1;
         when ("AFIB")  First_AFIB=1;
         when ("Seizure") First_Seizure=1;
         otherwise;
      end;
   end;
   else do;
      select (Icd_text);
         when ("Ischemic Stroke") Recurrent_IS=1;
         when ("Hemorrhagic Stroke") Recurrent_HS=1;
         when ("AFIB")  Recurrent_AFIB=1;
         when ("Seizure") Recurrent_Seizure=1;
         otherwise;
      end;
   end;
run;

Most of the code is to get single observation per date/topic to identify "first".

But I still think the description of what you want is not clear.

Note that the format is assigning N/A to anything that you didn't mention was of interest. The values are still in the data but if they are to be used for anything likely more details are needed.

View solution in original post

3 REPLIES 3
ballardw
Super User

If you are going to post data step code please post it into a text box opened on the forum with the </>. The main message windows will reformat pasted text and  your data step does not run as intended because of changes in column counts not matching your input statement.

 

Some details are missing. For one, I suspect all of this is supposed to be for each ID?

 

You say " the initial/first ever cancer diagnosis (Ischemic Stroke or Hemorrhagic Stroke)", which is it Cancer or stroke? You don't provide any actual details to identify cancer and I know from family history that Ischemic Stroke is not cancer.

 

Your repeatedly say "create a label". Does this mean a variable with the name Label? (which has issues around records that would need multiple 'label's) Or create a variable named "Recurrent", for example with some value? Which means we need to know the value you want.

 

You seem to have some of the ICD 9 and 10 codes listed of interest (example AFIB and Seizure) but don't have ICD 10 for the others. So are the lists actually complete? You also have the same ICD codes in multiple descriptions Ischemic Stroke, Hemorrhagic Stroke and Recurrent Ischemic Stroke. Are we supposed to have some additional rules as to which is which or is this just a not very clear description of some use of the ICD code.

 

So can you provide an example of what you expect the output to look like for at least one ID with AFIB and one with seizure?

 

ballardw
Super User

Here is one way that works with the example data to identify first/subsequent by topic of interest

proc sort data=have;
   by id diag_dt dx1-dx3;
run;
/* the sort and transpose by multiple variables is because of 
/* multiple rows of data with the same date*/
/* and need to filter the output to get one ICD value per observation*/
proc transpose data=have out=trans ( where=(not missing(ICD1)) drop=_name_ dx1-dx3)
   prefix=ICD;
   by id diag_dt dx1-dx3;
   var dx1-dx3;
run;

proc format library=work;
  value $icd 
  '433', '434', '436', 'I63', 'I693', 'G459' = "Ischemic Stroke"
  '430', '431', '4320', '4321', '4329', 'I60', 'I61', 'I62' = "Hemorrhagic Stroke"
  '42731', 'I480', 'I481', 'I482', 'I489' = "AFIB"
  '345', '78039', '6494', 'G40'= "Seizure"
  other='N/A'
  ;
run;

data helpful;
   set trans;
   ICD_text = put(icd1,$icd.);
run;

proc sort data=helpful;
   by id ICD_text  diag_dt;
run;

data need;
   set helpful;
   by id ICD_text  diag_dt;
   if first.ICD_text then do;
      select (Icd_text);
         when ("Ischemic Stroke") First_IS=1;
         when ("Hemorrhagic Stroke") First_HS=1;
         when ("AFIB")  First_AFIB=1;
         when ("Seizure") First_Seizure=1;
         otherwise;
      end;
   end;
   else do;
      select (Icd_text);
         when ("Ischemic Stroke") Recurrent_IS=1;
         when ("Hemorrhagic Stroke") Recurrent_HS=1;
         when ("AFIB")  Recurrent_AFIB=1;
         when ("Seizure") Recurrent_Seizure=1;
         otherwise;
      end;
   end;
run;

Most of the code is to get single observation per date/topic to identify "first".

But I still think the description of what you want is not clear.

Note that the format is assigning N/A to anything that you didn't mention was of interest. The values are still in the data but if they are to be used for anything likely more details are needed.

CathyVI
Pyrite | Level 9

@ballardw  Thank you. Your coding is very helpful. Now I would like to identify "Pre" and "Post first stroke"  for AFIB and ONLY "Post Stroke" for Seizure. I will put my code in </> moving forward. 

 

You say " the initial/first ever cancer diagnosis (Ischemic Stroke or Hemorrhagic Stroke)", which is it Cancer or stroke? You don't provide any actual details to identify cancer and I know from family history that Ischemic Stroke is not cancer.

Answer:I mean initial stroke NOT cancer.

 

Your repeatedly say "create a label". Does this mean a variable with the name Label? (which has issues around records that would need multiple 'label's) Or create a variable named "Recurrent", for example with some value? Which means we need to know the value you want.

Answer: I want to create a variable named "Recurrent", with 1 or 0.

 

You seem to have some of the ICD 9 and 10 codes listed of interest (example AFIB and Seizure) but don't have ICD 10 for the others. So are the lists actually complete?

Answer: There are multiple icd codes per record but I am only interested in AFIB & seizure. For example 1 patient may have dx of AFIB, stroke , eye infection but am only interested in the AFIB and stroke. 

You also have the same ICD codes in multiple descriptions Ischemic Stroke, Hemorrhagic Stroke and Recurrent Ischemic Stroke. Are we supposed to have some additional rules as to which is which or is this just a not very clear description of some use of the ICD code.

Answer: Same code should be use as initial and recurrent Ischemic Stroke or Hemorrhagic Stroke, the rule that applies is first icd will be the "initial" and  other repeated code will be "recurrent".

 

So can you provide an example of what you expect the output to look like for at least one ID with AFIB and one with seizure?

Answer: 

I would like to have variables "Pre" and "Post"  initial stroke depending on the encounter date and initial stroke date.

Id

diagnosis_dt

_label_

Icd1

icd_text  

First_IS

First_HS

First_AFIB

Recurrent AFIB

Pre- first stroke

Post-first stroke

0987234

08MAY2003

dx1

42731

AFIB

 

 

    1

 

1

 

0987234

30JUL2006

dx1

4321

Hemorr Stroke

.

1

.

 

.

 

0987234

14AUG2006

dx2

42731

AFIB

.

.

.

1

.

1

 

 

 

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 438 views
  • 0 likes
  • 2 in conversation