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?
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;
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;
@ReezaI am the original poster and thank you for your solution. I think the other poerson is probably looking for the same thing.
@Reeza Once again, thank you very much for your help!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.