BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
tan-wongv
Obsidian | Level 7

I successfully grouped the diagnosis code into disease classes and label it as "yes" for each DMRN. This is how the outcome looks like:

DMRN DX_CODE DX_NAME nervous circular respiratory genitourinary constipation DM
7 I10 hypertension   Yes        
7 J44.9 COPD     Yes      
7 M19.90 Arthritis            
7 N40.0 BPH       Yes    

 

Then, I would like to collapse the rows so that each DMRN has only one row and drop DX_CODE and DX_NAME.
This is how I want the table look like:

DMRN

nervous

circular respiratory genitourinary constipation DM
7   Yes Yes Yes    

 

What codes should I use? Thank you so much for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @tan-wongv,

 

Make sure that your dataset ("HAVE") is sorted by DMRN and then use a DATA step with an UPDATE statement:

data want;
update have(drop=dx: obs=0) have(drop=dx:);
by dmrn;
run;

This code drops variables whose names start with "DX" and creates one observation for each DMRN, containing the last non-missing value (if any) of NERVOUS, CIRCULAR, etc.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hello @tan-wongv,

 

Make sure that your dataset ("HAVE") is sorted by DMRN and then use a DATA step with an UPDATE statement:

data want;
update have(drop=dx: obs=0) have(drop=dx:);
by dmrn;
run;

This code drops variables whose names start with "DX" and creates one observation for each DMRN, containing the last non-missing value (if any) of NERVOUS, CIRCULAR, etc.

tan-wongv
Obsidian | Level 7

Thank you so much for your help! I appreciate your explanation 😊

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 546 views
  • 0 likes
  • 2 in conversation