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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 828 views
  • 4 likes
  • 2 in conversation