Fluorite | Level 6

## How to calculate the proportion of a modality of a binary variable in proc tabulate?

`I have data on 50 (20 girls, 30 boys) students.I have a total of 35 (15 Girls, 20 Boys) students who passed their Maths exam. In my database I have 3 variables: Gender,nb_books , result. The results variable is a binary variable taking the values ​​Yes or No. (Yes if the student passed his Mathematics exam, No if the student failed). I want to create a summary table where in columns I will have the sum of the number of books in mathematics, number ofstudent that passed the exam and the proportion of students who passed the exam. And I will have on the line the variablegender. But I don't know how to calculate the proportions in the table. `
`I converted the result variable into a  numeric variable named num_result.So I created a prob variable by using variable result defined as follows: - 1/20 if it is a girl who passed her exam -0 if it is a girl who did not pass her exam. -1/30 if it is a boy who passed his exam -0 if it is a boy who did not pass his exam.And I used sum in a proc tabulate to get the summary table.`
`But the total for the prob variable exceeds 1. Which is not good because I want it to equal 35/50. I used this code. I will appreciate your help.I used SAS EG. See my attached files for examples.`
``````proc tabulate data=students;
var num_result nb_books prob;
class gender;
TABLE
/* Row statement */
gender
all = 'Total',
/* column statement */
(num_result = ' ' * Sum={LABEL="Number of student that passed the exam"} nb_books = ' ' * Sum={LABEL="Number of mathematics books"} prob= ' ' * Sum={LABEL= " Proportion of student who passed the exam" );
;
RUN;``````
` `
` `
2 REPLIES 2
SAS Super FREQ

## Re: How to calculate the proportion of a modality of a binary variable in proc tabulate?

There are many ways to do this.... are you required to use PROC SUMMARY? I would use PROC FREQ for this task, as follows:

``````data Students;
length Sex \$6;
input Sex \$ Count Pass;
datalines;
Male 20 1
Male 10 0
Female 15 1
Female  5 0
;

proc freq data=Students;
tables Sex*Pass / norow nocol out=FreqOut;
weight Count;
run;

proc print data=FreqOut;
run;

``````
Fluorite | Level 6

## Re: How to calculate the proportion of a modality of a binary variable in proc tabulate?

`Thank you for your reply. I have summarized the problem. Otherwise I work with a big data where I will have three variables of respective alphanumeric, numeric and binary types. And I want to write a program that will output me that every time my data changes a table in the same format as in the word document.`
Discussion stats
• 2 replies
• 614 views
• 0 likes
• 2 in conversation