BookmarkSubscribeRSS Feed
Child79
Fluorite | Level 6
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
Rick_SAS
SAS Super FREQ

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;

Child79
Fluorite | Level 6
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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 1074 views
  • 0 likes
  • 2 in conversation