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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

@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;
--
Paige Miller
Reeza
Super User
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!


 

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

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 792 views
  • 3 likes
  • 3 in conversation