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?
@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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.