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

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? 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

6 REPLIES 6
pearsoninst
Pyrite | Level 9
I tried for last one hr and could not fine the answer ..can some one help ..
Reeza
Super User

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;
Reeza
Super User
@pearsoninst I'm confused, you're not the original poster?
jackchanheikit
Fluorite | Level 6

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

jackchanheikit
Fluorite | Level 6

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

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!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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