Help using Base SAS procedures

Creating a Variable using Dates

Reply
Occasional Contributor
Posts: 11

Creating a Variable using Dates

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?

Super User
Posts: 20,679

Re: Creating a Variable using Dates


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. 

Ask a Question
Discussion stats
  • 1 reply
  • 131 views
  • 0 likes
  • 2 in conversation