BookmarkSubscribeRSS Feed
str8gone24
Fluorite | Level 6

Hello,

 

I have a group of variables that describe what procedure a patient got (up to 15 procedures) that are ICD-9 codes in strings (e.g. "6701") that are PR1, PR2.....PR15. 

 

Another group of variables are the day on which those procedures happen (e.g. 1, 2, 5, 10...) that are PRDAY1, PRDAY2....PRDAY15.

 

How do I match up what day a SPECIFIC procedure happened? e.g. I need a variable that tells me that patient got procedure 6701 (Surgery) on day 6.

 

These are how the procedure variables have been labeled thus far:

 

Data Inpatients;

array PR {15} PR1-15;

do k=1 to 15;

if PR{k] = '6701] then Surgery =1

etc.

end;

 

Thank you!

 

I'm using SAS 9

 

 

6 REPLIES 6
str8gone24
Fluorite | Level 6

What I've tried, not sure if this makes sense:

 

 

Data Dataset;

set Dataset;

array PR {15} PR1-15;

do k=1 to 15;

array PRDAY {15} PRday1-15;

do k=1 to 15; if PR{k} = '6701' then Surgeryvar=PRday{k};

run;

Astounding
PROC Star

You're on the right track.  One thing that stands out as needing to be changed:  how you specify a list of variables.  The right way:

 

array PR {15} PR1-PR15;

array PRDAY {15} PRday1-PRday15;

 

It's possible that this is the only change you need to make.  Try it and see what you get.

 

Also, consider what you would like to do if the patient had two surgeries, and you would need two variables to hold the dates.

str8gone24
Fluorite | Level 6
Oh gosh you're right about needing two variables if two surgeries. I'm trying to see if two procedures ever happened on the same day and I thought I needed one variable for each procedure day and then i got just see when they matched, but now....
Astounding
PROC Star

OK, here's a step in that direction:

 

Data want;

set have;

array PR {15} PR1-PR15;

array PRDAY {15} PRday1-PRday15;

do k=1 to 15;

   if PR{k} = '6701' then do;

      if surgeryvar1 = . then Surgeryvar1=PRday{k};

      else Surveryvar2=PRday{k};

   end;

end;

run;

Reeza
Super User
Can you please provide a small sample of how your data looks like and what you want as output?
Reeza
Super User
You would be better off transposing your data then you don't have this issue. If your data is organized as

ID Procedure Procedure_Date Procedure_Count
1 6701 01Jan2018 1
2 4533 03Jan2018 1
1 6701 01Jan2017 1
...

Then you could do:

data want;
set have;
where procedure in (6701);
run;

In general, this structure is more useful for answering a variety of questions.

I worked with healthcare data for over 5 years and have found this data structure to be optimal. Here's a tutorial on transforming your data:
https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 1083 views
  • 0 likes
  • 3 in conversation