02-07-2016 09:31 PM - edited 02-07-2016 09:37 PM
I have students who get ratings on their courses. I need to know how many total 'Excellent' and 'Satisfactory' each student (by group in this case) got regardless of their course. Can someone help please. Thank you.
ID Name Course Skill_Name Rating
10 Jack English Writing Excellent
10 Jack English Listening Satisfactory
10 Jack English Learning Good
10 Jack Biology Writing Excellent
10 Jack Biology Listening Satisfactory
10 Jack Biology Learning Satisfactory
13 Jill Math Writing Excellent
13 Jill Math Listening Satisfactory
13 Jill Math Learning Good
13 Jill Biology Writing Excellent
13 Jill Biology Listening Excellent
13 Jill Biology Learning Good
Output table will be:
ID Name Excellent Satisfactory
10 Jack 2 3
13 Jill 3 1
02-08-2016 06:16 PM
If I may step in here: Yes, you can add ID as an additional "factor" to the TABLE statement, in which case it's useful to add the LIST option so as to keep all combinations in one table:
table ID*Name*Rating / nopct list;
By using the OUT= option and applying PROC TRANSPOSE to the output dataset, you could even get exactly the output table you had envisaged in your original post:
proc freq data=have; table ID*Name*Rating / nopct list out=cnt; run; proc transpose data=cnt out=want(drop=_:); where rating in: ('Exc', 'Sat'); by id name; var count; id rating; run; proc print data=want; run;
02-08-2016 08:51 AM
Assuming you want a data set in the format that you have shown ...
Assuming that your data set is already sorted by ID ...
Here is one way to program it:
if first.ID then do;
if rating='Excellent' then excellent + 1;
else if rating='Satisfactory' then satisfactory + 1;
Need further help from the community? Please ask a new question.