BookmarkSubscribeRSS Feed
PSU_Sudzi
Obsidian | Level 7

Hello Folks,

 

I am creating a listing merging all Med History, Con Meds, and AEs for manual review to catch items that may be recorded in one place but missing in others, e.g. an Indication for Con Meds that is missing from either MH or AE or a worsening AE missing an MH entry with original diagnosis. It came out nicely but because the only item in common I have with all 3 tables is the subject number, it will duplicate some items. In a small example of the output, you can see that MEDICATION #2 is duplicated in the output since there are 4 AEs but only 2 Con Meds. Is there a way to modify my code to remove the additional entries of MEDICATION #2 on the output, so that it would only appear the first time and then be blank? Code posted below.

 

options mergenoby=error;
data study1.mhcmae;
merge study1.mh study1.cm study1.ae;
by subj;
run;

 

MedicationIndicationAdverse Event
MEDICATION #1INDICATION #1AE #1
MEDICATION #2INDICATION #2AE #2
MEDICATION #2INDICATION #2AE #3
MEDICATION #2INDICATION #2AE #4
2 REPLIES 2
Tom
Super User Tom
Super User

That is how SAS does a merge. If one of the datasets stops contributing observations the values of the variables unique to that dataset never get changed.  That is why 1 to Many merges work well.

 

For your report you can just use CALL MISSING() to reset ALL of the variables.  Then the datasets that are still contributing will update their variables and the variables from the ones that have run out will remain missing. 

 

Remember to write the current observation first.

data study1.mhcmae;
  merge study1.mh study1.cm study1.ae;
  by subj;
  output;
  call missing(of _all_);
run;

 

PSU_Sudzi
Obsidian | Level 7

Hi Tom, thanks so much, this makes the output look 10 times better! You're help is appreciated.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 804 views
  • 1 like
  • 2 in conversation