The SAS Output Delivery System and reporting techniques

How to Output Category with No Count in Proc Tabulate

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

How to Output Category with No Count in Proc Tabulate

I am trying to make a percentage table for a survey using proc tabulate. All questions have 8 choices. However, since not all choices will be chosen in the survey for each questions, SAS will skip those choices. Is there away to have SAS to output it as 0 instead of skipping it? 

 

Please see the sample code below: 

 

data test;
input participant Question_A Question_B;
datalines;
1 4 2
2 3 0
3 6 5
4 1 0
5 0 4
6 6 4
7 7 7
8 1 0
9 4 2
10 1 4
11 3 2
12 1 4
13 3 0
14 3 4
15 3 3
16 1 7
17 2 3
18 5 4
19 6 0
20 5 6
;
run;

proc format;
value testfmt
/* 0='0'*/
/* 1='Strongly Disagree'*/
/* 2='Disagree'*/
/* 3='Slightly Disagree'*/
/* 4='No opinion (Neutral)'*/
/* 5='Slightly Agree'*/
/* 6='Agree (Mostly Agree)'*/
/* 7='Strongly Agree';*/
0='0'
1='1'
2='2'
3='3'
4='4'
5='5'
6='6'
7='7';
run;

proc tabulate data = test;
class
Question_A
Question_B
;
table (
Question_A
Question_B
),pctn<
Question_A
Question_B
>="%"*f=5.0;
format
Question_A
Question_B
testfmt.;
run;

 

In this case, none of the particpant reponsed for choice 1 for question B. Thus choice 1 does not show up in the table from proc tabulate. However, is there a way to have SAS output choice 1 as 0 percent? 


Accepted Solutions
Solution
‎11-24-2015 05:34 PM
Super User
Posts: 19,860

Re: How to Output Category with No Count in Proc Tabulate

[ Edited ]
Posted in reply to pearsoninst

PRELOADFMT on class statement

and PRINTMISS on table statement. 

Method 3 in the paper above.

proc tabulate data = test ;
class Question_A Question_B / preloadfmt;
table (Question_A Question_B), pctn<Question_A Question_B>="%"*f=5.0/printmiss;
format Question_A Question_B testfmt.;
run;

View solution in original post


All Replies
Super User
Posts: 19,860

Re: How to Output Category with No Count in Proc Tabulate

Posted in reply to jackchanheikit
Frequent Contributor
Posts: 108

Re: How to Output Category with No Count in Proc Tabulate

I tried for last one hr and could not fine the answer ..can some one help ..
Solution
‎11-24-2015 05:34 PM
Super User
Posts: 19,860

Re: How to Output Category with No Count in Proc Tabulate

[ Edited ]
Posted in reply to pearsoninst

PRELOADFMT on class statement

and PRINTMISS on table statement. 

Method 3 in the paper above.

proc tabulate data = test ;
class Question_A Question_B / preloadfmt;
table (Question_A Question_B), pctn<Question_A Question_B>="%"*f=5.0/printmiss;
format Question_A Question_B testfmt.;
run;
Super User
Posts: 19,860

Re: How to Output Category with No Count in Proc Tabulate

Posted in reply to pearsoninst
@pearsoninst I'm confused, you're not the original poster?
Occasional Contributor
Posts: 5

Re: How to Output Category with No Count in Proc Tabulate

@ReezaI am the original poster and thank you for your solution. I think the other poerson is probably looking for the same thing. 

Occasional Contributor
Posts: 5

Re: How to Output Category with No Count in Proc Tabulate

@Reeza Once again, thank you very much for your help! 

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 513 views
  • 2 likes
  • 3 in conversation