BookmarkSubscribeRSS Feed
ellieokay
Calcite | Level 5

I am using SAS 9. Let's say my data appears as the following: 

 

Pt         Disease1        Disease2      Disease3     Disease4      

1               .                    1                       .              1

2               .                    .                       1              .                   

3               1                   .                       .               .

4               .                    .                       .               1

5               1                   .                       1              .

6               .                    1                      .               .

 

Most of my patients only have one disease, but I would like to capture patients with multiple diseases, so desired output would be 

Pt         Disease1          Disease2     Disease3     Disease4

1                .                     1                     .               1

5                1                     .                     1               .

 

I've tried something like "if (disease1 and disease2 and disease3 and disease4) ge 2 then diseaseMult=1" but that is not working. Is there a way to say something like "if at least 2 of (disease1 and disease2 and disease3 and disease4)=1 then diseaseMult=1"? 

 

Thanks! 

 

1 REPLY 1
novinosrin
Tourmaline | Level 20

data have;
input Pt         Disease1        Disease2      Disease3     Disease4      ;
cards;
1               .                    1                       .              1
2               .                    .                       1              . 
3               1                   .                       .               .
4               .                    .                       .               1
5               1                   .                       1              .
6               .                    1                      .               .
;

data want;
set have;
if sum(of disease:)>1;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1 reply
  • 742 views
  • 1 like
  • 2 in conversation