- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-25-2022 01:40 PM
(736 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.