Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Re: How to calculate the proportion of a modality of a binary variable...

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-25-2022 01:40 PM
(614 views)

`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 of

student that passed the exam and the proportion of students who passed the exam. And I will have on the line the variable

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 25. Read more here about **why** you should contribute and **what is in it** for you!

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.