BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

 

I have been struggling with one sas coding from encounter level to patient level. Please help.
 
So my data is like:
 
ID dx_encounter level
1 1
1 0
1 0
1 1
2 0
2 0
2 0
3 1
3 0
3 0
 
I want to create the variable "dx_patient level" where if each patient ID received any "1" from "dx_encounter level", then "dx_patient level" should be 1. Otherwise it's 0.
 
The data I want is : 
ID dx_encounter level dx_patient level
1 1 1
1 0 1
1 0 1
1 1 1
2 0 0
2 0 0
2 0 0
3 1 1
3 0 1
3 0 1
 Thank you!
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Some options:
Find the maximum and merge it in.
Use SQL to join and merge in the maximum.

Since 1 is always first in your examples, use RETAIN on first value and carry forward.

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

Retain tutorial:
https://sascrunch.com/retain-statement/

View solution in original post

1 REPLY 1
Reeza
Super User
Some options:
Find the maximum and merge it in.
Use SQL to join and merge in the maximum.

Since 1 is always first in your examples, use RETAIN on first value and carry forward.

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas

Retain tutorial:
https://sascrunch.com/retain-statement/

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

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 404 views
  • 1 like
  • 2 in conversation