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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3950 views
  • 3 likes
  • 3 in conversation