BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jcapua2
Fluorite | Level 6

Hello,

 

data have;

patient_numProcedure DateStatus DateOrgan
patient1103/07/200202/23/2004Heart
patient1102/23/200410/01/2014Lung
patient1204/23/200610/13/2014Heart
patient1310/21/200710/10/2016Bone
patient1405/06/200904/30/2017Liver
patient1405/09/201007/15/2017Liver

 

data want;

patient_numProcedure DateStatus DateOrganMultiorgan
patient1103/07/200202/23/2004HeartYes
patient1102/23/200410/01/2014LungYes
patient1204/23/200610/13/2014HeartNo
patient1310/21/200710/10/2016BoneNo
patient1405/06/200904/30/2017LiverNo
patient1405/09/201007/15/2017LiverNo

 

I want to flag rows where a patient has multiple organ procedures. So for patient 11, he/she has both heart and lung surgeries. So new variable Multiorgan='Yes'.

 

Is there a way to do this in data step? Or proc SQL?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

SQL is quicker in this case.

 

proc sql;
create table want as
select *, 
      case when max(organ)=min(organ) then 'No'
                   else 'Yes' end 
      as multiorgan
from have
group by patient_num;
quit;

View solution in original post

2 REPLIES 2
Reeza
Super User

SQL is quicker in this case.

 

proc sql;
create table want as
select *, 
      case when max(organ)=min(organ) then 'No'
                   else 'Yes' end 
      as multiorgan
from have
group by patient_num;
quit;
mkeintz
PROC Star

 

 If the data are sorted by patient_num:

 

data want;

  set have;

  by patient_num;

  if first.patient_num and last.patient_num then multi_organ='No';

  else multi_organ='Yes';

run;

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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