Hello,
I am using SAS 9.4 and am trying to figure out how to compress/summarize a group of data together.
EXAMPLE:
code: OLD
patient Disease1 Disease2 Disease 3 Disease 4 Disease 5 Disease 6
1 0 1 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
1 0 0 1 0 0 0
1 0 0 0 0 1 0
1 1 0 0 0 0 0
1 0 0 0 1 0 0
2 0 0 0 0 0 1
2 1 0 0 0 0 0
2 0 0 0 0 0 0
2 0 1 0 0 0 0
2 0 0 1 0 0 0
2 1 0 0 0 0 0
2 0 0 0 0 0 1
code: NEW
patient Disease 1 Disease 2 Disease 3 Disease 4 Disease 5 Disease 6
1 1 1 1 1 1 0
2 1 1 1 0 0 1
This is multiple encounters with the above two patients and have been diagnosed each time. The 1's and 0's show if the disease is present or not. Taking the old data above, I would like to basically compress the old data into only one row per patient showing if they have the disease or not by using 1 or 0. I am not sure where to even start in this kind of coding.
Any help would be appreciated,
Thanks!
@Kbug wrote:
Hello,
I am using SAS 9.4 and am trying to figure out how to compress/summarize a group of data together.
EXAMPLE:
code: OLD
patient Disease1 Disease2 Disease 3 Disease 4 Disease 5 Disease 6
1 0 1 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
1 0 0 1 0 0 0
1 0 0 0 0 1 0
1 1 0 0 0 0 0
1 0 0 0 1 0 0
2 0 0 0 0 0 1
2 1 0 0 0 0 0
2 0 0 0 0 0 0
2 0 1 0 0 0 0
2 0 0 1 0 0 0
2 1 0 0 0 0 0
2 0 0 0 0 0 1
code: NEW
patient Disease 1 Disease 2 Disease 3 Disease 4 Disease 5 Disease 6
1 1 1 1 1 1 0
2 1 1 1 0 0 1
This is multiple encounters with the above two patients and have been diagnosed each time. The 1's and 0's show if the disease is present or not. Taking the old data above, I would like to basically compress the old data into only one row per patient showing if they have the disease or not by using 1 or 0. I am not sure where to even start in this kind of coding.
Any help would be appreciated,
Thanks!
proc summary data=have;
class patient;
var disease1-disease6;
output out=want max=;
run;
@Kbug wrote:
Hello,
I am using SAS 9.4 and am trying to figure out how to compress/summarize a group of data together.
EXAMPLE:
code: OLD
patient Disease1 Disease2 Disease 3 Disease 4 Disease 5 Disease 6
1 0 1 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
1 0 0 1 0 0 0
1 0 0 0 0 1 0
1 1 0 0 0 0 0
1 0 0 0 1 0 0
2 0 0 0 0 0 1
2 1 0 0 0 0 0
2 0 0 0 0 0 0
2 0 1 0 0 0 0
2 0 0 1 0 0 0
2 1 0 0 0 0 0
2 0 0 0 0 0 1
code: NEW
patient Disease 1 Disease 2 Disease 3 Disease 4 Disease 5 Disease 6
1 1 1 1 1 1 0
2 1 1 1 0 0 1
This is multiple encounters with the above two patients and have been diagnosed each time. The 1's and 0's show if the disease is present or not. Taking the old data above, I would like to basically compress the old data into only one row per patient showing if they have the disease or not by using 1 or 0. I am not sure where to even start in this kind of coding.
Any help would be appreciated,
Thanks!
proc summary data=have;
class patient;
var disease1-disease6;
output out=want max=;
run;
proc means data=have max;
by patient;
var disease1-disease6;
output out=want max = ;
run;
You essentially want the maximum value for each column, ie if it's ever 1 it stays as 1.
Check that the WANT data set has what you want. You may need to sort your data ahead of time, if needed.
@Kbug wrote:
Hello,
I am using SAS 9.4 and am trying to figure out how to compress/summarize a group of data together.
EXAMPLE:
code: OLD
patient Disease1 Disease2 Disease 3 Disease 4 Disease 5 Disease 6
1 0 1 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
1 0 0 1 0 0 0
1 0 0 0 0 1 0
1 1 0 0 0 0 0
1 0 0 0 1 0 0
2 0 0 0 0 0 1
2 1 0 0 0 0 0
2 0 0 0 0 0 0
2 0 1 0 0 0 0
2 0 0 1 0 0 0
2 1 0 0 0 0 0
2 0 0 0 0 0 1
code: NEW
patient Disease 1 Disease 2 Disease 3 Disease 4 Disease 5 Disease 6
1 1 1 1 1 1 0
2 1 1 1 0 0 1
This is multiple encounters with the above two patients and have been diagnosed each time. The 1's and 0's show if the disease is present or not. Taking the old data above, I would like to basically compress the old data into only one row per patient showing if they have the disease or not by using 1 or 0. I am not sure where to even start in this kind of coding.
Any help would be appreciated,
Thanks!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.