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

Hello,

I have a dataset as below:

data have;
input exam $ passed;
datalines;
A 0
A 1
B 1
C 0
D 1
E 0
E 1
;
run;

Using tabulate procedure i am able to generate total counts correctly, but in ColPctn, i would like to have percentages within in each exam. for instance: first row of output should

be 50% (1 passed / 2 all) = 0.5 , and not 

This is the code i am using below  :
title "CrossTab";

proc tabulate data = have;
class exam;
var passed;
table exam ,
passed*( N SUM='Passed'*f= 10. colpctn);
keylabel all = "Total";
run;

and the output which is not coming as i need:

  passed
N Passed ColPctN
exam 2 1 28.57
A
B 1 1 14.29
C 1 0 14.29
D 1 1 14.29
E 2 1 28.57

I would appreciate any suggestion .

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Percentages can be tricky but in this case there is an easy solution:

proc tabulate data = have;
class exam;
var passed;
table exam ,
passed*( N SUM='Passed'*f= 10. mean='% Passed'*f=percent8.2);
keylabel all = "Total";
run;

When dealing with a 0/1 variable, the mean is the same as the percentage of "1" values.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Percentages can be tricky but in this case there is an easy solution:

proc tabulate data = have;
class exam;
var passed;
table exam ,
passed*( N SUM='Passed'*f= 10. mean='% Passed'*f=percent8.2);
keylabel all = "Total";
run;

When dealing with a 0/1 variable, the mean is the same as the percentage of "1" values.

sascode
Quartz | Level 8
Thank you 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
  • 2 replies
  • 451 views
  • 4 likes
  • 2 in conversation