BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9

data EVTQBP EVTnotQBP;
merge EVT.EVT_hometime(in=INfullcohort) EVT.Evt_qbp(in=INQBP);
by CIHI_KEY;
if INfullcohort =1 and INQBP=0 then output EVTnotQBP;
ELSE output EVTQBP;
run;
EVT.Home time data set has 696 keys and EVT.Evt_qbp has 687 keys
I am trying to write out the 9 keys in the EVTnotQBP dataset and want to know if my code is doing it correctly?
Also in the EVTQBP dataset I want to write out the keys that are only present in the EVT.Evt_qbp dataset which has 687 observations
Is my code correct to get the desired output?

7 REPLIES 7
mkeintz
PROC Star

This comment assumes your have one record per key in each data set.

 

Just because hometime has 696 unique key values and evt_qbp has 687 values does NOT mean there will be 9 keys in EVTnotQBP ... UNLESS  you know that evt_qbp is a proper subset of hometime (i.e. no keys in evt_qbp that are not also in evt_hometime).  

 

As to your code, it should work, but you don't really need the INfullcohort dummy.  You could just:

 

data EVTQBP EVTnotQBP;
  merge EVT.EVT_hometime EVT.Evt_qbp (in=inqbp);
  by CIHI_KEY;
  if INQBP = 0 then output EVTnotQBP;
  ELSE output EVTQBP;
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

--------------------------
Ranjeeta
Pyrite | Level 9

Why is it tat i dont need the infull cohort marker ?

 

mkeintz
PROC Star

If you know that evt_qbp is a proper subset of evt_hometime, then having in= dummy for evt_hometime would result in that dummy getting a value of 1 for every merged observation.  I.e. it would effectively be a constant, and offer no discriminatory power.

--------------------------
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

--------------------------
Ranjeeta
Pyrite | Level 9
EVT QBp is a proper subset of hometime as I got 0 observations for the following if condition
else if inqbp = 1 and infullcohort=0 then output; Now if I need the cases that are only in QBP then saying if INfullcohort =1 and INQBP=1 then output; would be correct right?
mkeintz
PROC Star

You've got all the tools presented to you.  It's time to experiment on sample data.   For this question, I suspect that will be far more valuable than an answer from even the most instructive forum response.

--------------------------
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

--------------------------
Ranjeeta
Pyrite | Level 9
Thanks
PGStats
Opal | Level 21

It would be safer to account for every possibility:

 

data evt_qbp_only evt_hometime_only evt_qbp_hometime;
merge EVT.EVT_hometime(in=INfullcohort) EVT.Evt_qbp(in=INQBP);
by CIHI_KEY;
if INfullcohort =1 and INQBP=0 then output evt_hometime_only;
if INfullcohort =0 and INQBP=1 then output evt_qbp_only;
if INfullcohort =1 and INQBP=1 then output evt_qbp_hometime;
run;
PG

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 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 934 views
  • 5 likes
  • 3 in conversation