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


Hi,

I'm having a bit of trouble making a listing out of my data and was hoping someone could point me in the right direction.

Below I've given a simplified version of my data. It consists of two patients (1001 and 1002) who came in on two different days (day01 and day02) to have two different tests (test01 and test02) which can have two different results (good or bad).


Patient   testday    test      result
1001      Day01     test01   good
1001      Day01    test02    bad
1001      Day02    test01   good
1001      Day02     test02  good
1002      Day01    test01  good
1002      Day01    test02  good
1002      Day02    test01  bad
1002      Day02    test02  bad

 

I would like to output the data in the following form:

 

Patient 1001:
            Day01 Day02
Test1    good   good
Test2     bad    good


Patient 1002:
           Day01 Day02
Test1  good    bad
Test2  good    bad

 

 

Now if the result variable was numeric I could make something like this quite easily using the tabulate procedure using a "table patient, test, testday*result" statement.

I can get something roughly equivalent using proc print and by variables but not exactly. I could also set about transposing the data into a new table and print that out.

However I think what I need to be using is the report procedure, but frankly I'm having little luck in working out what I need to do.

If someone could point me in the right direction that would be terrific.

Many thanks. 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
How about :
data have;
input Patient   (testday    test      result) ($);
cards;
1001      Day01     test01   good
1001      Day01    test02    bad
1001      Day02    test01   good
1001      Day02     test02  good
1002      Day01    test01  good
1002      Day01    test02  good
1002      Day02    test01  bad
1002      Day02    test02  bad
;
run;

proc report data=have nowd;
by Patient;
columns test testday,result;
define test/group ' ';
define testday/across ' ';
define result/group ' ';
run;

View solution in original post

2 REPLIES 2
Ksharp
Super User
How about :
data have;
input Patient   (testday    test      result) ($);
cards;
1001      Day01     test01   good
1001      Day01    test02    bad
1001      Day02    test01   good
1001      Day02     test02  good
1002      Day01    test01  good
1002      Day01    test02  good
1002      Day02    test01  bad
1002      Day02    test02  bad
;
run;

proc report data=have nowd;
by Patient;
columns test testday,result;
define test/group ' ';
define testday/across ' ';
define result/group ' ';
run;

StephenM
Fluorite | Level 6
Thank you. This helps clarify the report procedure a lot for me.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1576 views
  • 0 likes
  • 2 in conversation