BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dhana18
Obsidian | Level 7
I have a data like this
				
PatientId 	Test A 	Test B	Test C 	Test D
1	0	1	1	0
2	0	0	0	1
3	0	1	0	0
4	1	0	0	1
5	1	1	1	0
6	0	0	0	1
7	1	1	0	0
8	0	0	0	1
9	0	1	1	0
10	0	0	0	1
11	0	1	0	0

I would like to know if patient is positive(1) in more than on test. how do i need to code?
Please help
			
          
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

With your data and assuming the Test.. variables are numeric and only have values of missing, 0 or 1 something like below should work.

data sample;
  infile datalines dlm=' ' truncover;
  input PatientId Test_A Test_B Test_C Test_D;
  outcome_flg= sum(of test_:) > 1;
  datalines;
1 0 1 1 0
2 0 0 0 1
3 0 1 0 0
4 1 0 0 1
5 1 1 1 0
6 0 0 0 1
7 1 1 0 0
8 0 0 0 1
9 0 1 1 0
10 0 0 0 1
11 0 1 0 0
;

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

With your data and assuming the Test.. variables are numeric and only have values of missing, 0 or 1 something like below should work.

data sample;
  infile datalines dlm=' ' truncover;
  input PatientId Test_A Test_B Test_C Test_D;
  outcome_flg= sum(of test_:) > 1;
  datalines;
1 0 1 1 0
2 0 0 0 1
3 0 1 0 0
4 1 0 0 1
5 1 1 1 0
6 0 0 0 1
7 1 1 0 0
8 0 0 0 1
9 0 1 1 0
10 0 0 0 1
11 0 1 0 0
;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 1 reply
  • 687 views
  • 0 likes
  • 2 in conversation