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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3983 views
  • 3 likes
  • 3 in conversation