Hi All,
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
PROC FREQ is a great proc for counting occurences.
proc freq data=have;
table Name*Rating/nopct;
run;
proc tabulate data=have;
class ID Name Rating;
where rating ne 'Good';
table id*name,Rating=''*n='';
run;
PROC FREQ is a great proc for counting occurences.
proc freq data=have;
table Name*Rating/nopct;
run;
Thanks Reeza, that's really helpful. Can you tell me how do I bring more than one variable to show up in the table. In this case ID in addition to Name.
Thanks,
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;
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:
data want;
set have;
by ID;
if first.ID then do;
excellent=0;
satisfactory=0;
end;
if rating='Excellent' then excellent + 1;
else if rating='Satisfactory' then satisfactory + 1;
if last.ID;
drop rating;
run;
Good luck.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.