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 .
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.
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.
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.
Ready to level-up your skills? Choose your own adventure.