BookmarkSubscribeRSS Feed
jcapua2
Fluorite | Level 6

Hello,

 

data have;

patient_numProcedure_DateOrganMultiorgan
patient331/24/2000HeartNo
patient335/13/2003KidneyYes
patient335/13/2003SkinYes
patient345/7/2007LungNo
patient345/27/2009HeartNo

 

data want;

patient_numProcedure_DateOrganMultiorganPrevious_organ
patient331/24/2000HeartNoNo
patient335/13/2003KidneyYesYes
patient335/13/2003SkinYesYes
patient345/7/2007LungNoNo
patient345/27/2009HeartNoYes

 

I want to create a new variable that flags whether a particular patient has had a previous organ procedure. For example, patient34 has 2 different Procedure_date, with a later Procedure_date that occurred with a different organ, flagging that later row with Previous_organ='Yes' but the prior row (the first Procedure_date) Previous_organ='No.'

 

Also, for patient33, with 3 Procedure_date, but the last 2 dates occurred on the same date but with different organs. It flags the last 2 dates as Previous_organ='Yes' but the prior row (the first Procedure_date) Previous_organ='No.'

 

Is there any way to do this in SQL or SAS data step?

1 REPLY 1
Reeza
Super User

@jcapua2 wrote:

Hello,

 

data have;

patient_num Procedure_Date Organ Multiorgan
patient33 1/24/2000 Heart No
patient33 5/13/2003 Kidney Yes
patient33 5/13/2003 Skin Yes
patient34 5/7/2007 Lung No
patient34 5/27/2009 Heart No

 

data want;

patient_num Procedure_Date Organ Multiorgan Previous_organ
patient33 1/24/2000 Heart No No
patient33 5/13/2003 Kidney Yes Yes
patient33 5/13/2003 Skin Yes Yes
patient34 5/7/2007 Lung No No
patient34 5/27/2009 Heart No Yes

 

I want to create a new variable that flags whether a particular patient has had a previous organ procedure. For example, patient34 has 2 different Procedure_date, with a later Procedure_date that occurred with a different organ, flagging that later row with Previous_organ='Yes' but the prior row (the first Procedure_date) Previous_organ='No.'

 

Also, for patient33, with 3 Procedure_date, but the last 2 dates occurred on the same date but with different organs. It flags the last 2 dates as Previous_organ='Yes' but the prior row (the first Procedure_date) Previous_organ='No.'

 

Is there any way to do this in SQL or SAS data step?


Look up first and last BY GROUP processing. Most of the questions you've asked can be answered using these techniques in a data step. 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 917 views
  • 0 likes
  • 2 in conversation