BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Barkat
Pyrite | Level 9

I have the following data set.

data have;
informat Week mmddyy8.;
input ID Group $ Week  Disease $ Result $   ;
Format week date7.;
cards;
01 A 12/03/22 X Pos 
02 A 12/03/22 Y Pos 
03 B 12/17/22 Z Neg
04 A 12/17/22 X Pos 
05 B 12/24/22 Y Pos
06 B 12/24/22 Z Neg
07 C 12/24/22 X Neg 
08 A 12/31/22 Y Pos
09 A 01/14/23 Z Neg
10 B 01/14/23 X Pos 
11 A 01/21/23 Y Pos
12 A 01/21/23 Z Neg
13 A 01/14/23 Z Neg
14 C 01/14/23 X Neg 
15 A 01/21/23 Y Pos
16 C 01/21/23 Z Neg
17 A 01/14/23 Z Neg
18 C 01/14/23 Y Neg 
19 B 01/21/23 Y Pos
20 C 01/21/23 Z Neg
;

I ran the code below to create a table. 

PROC TABULATE data=have missing ;
CLASS Disease Result ;
TABLE Disease all="Total",  Result * N='' ;
Where group = "C" ;
RUN;

I do not see the  "Pos" column in the output table since there is no "Pos" in the "result" column where group="C". However, I would like to keep the "Pos" column in the output with zero value.

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I think a pre-Loaded format is one way.  With an extra option or two.

 

 

data have;
informat Week mmddyy8.;
input ID Group $ Week  Disease $ Result $   ;
Format week date7.;
cards;
01 A 12/03/22 X Pos 
02 A 12/03/22 Y Pos 
03 B 12/17/22 Z Neg
04 A 12/17/22 X Pos 
05 B 12/24/22 Y Pos
06 B 12/24/22 Z Neg
07 C 12/24/22 X Neg 
08 A 12/31/22 Y Pos
09 A 01/14/23 Z Neg
10 B 01/14/23 X Pos 
11 A 01/21/23 Y Pos
12 A 01/21/23 Z Neg
13 A 01/14/23 Z Neg
14 C 01/14/23 X Neg 
15 A 01/21/23 Y Pos
16 C 01/21/23 Z Neg
17 A 01/14/23 Z Neg
18 C 01/14/23 Y Neg 
19 B 01/21/23 Y Pos
20 C 01/21/23 Z Neg
;
proc format; value $result(notsorted) 'Neg'='Neg' 'Pos'='Pos'; quit;
PROC TABULATE data=have missing;
   CLASS Disease;
   class Result / preloadfmt order=data;
   format result $Result.;
   TABLE Disease all="Total",  Result * N='' / printmiss misstext='0';
   Where group = "C" ;
   run;

   

View solution in original post

1 REPLY 1
data_null__
Jade | Level 19

I think a pre-Loaded format is one way.  With an extra option or two.

 

 

data have;
informat Week mmddyy8.;
input ID Group $ Week  Disease $ Result $   ;
Format week date7.;
cards;
01 A 12/03/22 X Pos 
02 A 12/03/22 Y Pos 
03 B 12/17/22 Z Neg
04 A 12/17/22 X Pos 
05 B 12/24/22 Y Pos
06 B 12/24/22 Z Neg
07 C 12/24/22 X Neg 
08 A 12/31/22 Y Pos
09 A 01/14/23 Z Neg
10 B 01/14/23 X Pos 
11 A 01/21/23 Y Pos
12 A 01/21/23 Z Neg
13 A 01/14/23 Z Neg
14 C 01/14/23 X Neg 
15 A 01/21/23 Y Pos
16 C 01/21/23 Z Neg
17 A 01/14/23 Z Neg
18 C 01/14/23 Y Neg 
19 B 01/21/23 Y Pos
20 C 01/21/23 Z Neg
;
proc format; value $result(notsorted) 'Neg'='Neg' 'Pos'='Pos'; quit;
PROC TABULATE data=have missing;
   CLASS Disease;
   class Result / preloadfmt order=data;
   format result $Result.;
   TABLE Disease all="Total",  Result * N='' / printmiss misstext='0';
   Where group = "C" ;
   run;

   

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 436 views
  • 3 likes
  • 2 in conversation