BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
YiqunDai
Fluorite | Level 6

I have a dataset as follows. And I want to get the percentage of students with A, B, or C for each class, is it possible to do by Proc SQL? Thank you so much.

--------------------

ID   Credit  Class

--------------------

1     A         1

2     B         1

3     B         1

4     C         1

5     A         1

6     A         2

7     C         2

8     C         2

9     C         2

10   B         2

-------------------

 

And the result I want to get is

-----------------------

Class  A    B    C

-----------------------

1        0.4  0.4  0.2

2        0.2  0.2  0.6

----------------------

1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

You can calculate the average of a boolean reponse:

 

data have;
    input credit $ class;
datalines;
A         1
B         1
B         1
C         1
A         1
A         2
C         2
C         2
C         2
B         2
;

proc sql;
    SELECT class, 
           mean(credit = 'A') 'A',
           mean(credit = 'B') 'B',
           mean(credit = 'C') 'C'
    FROM have
    GROUP BY class;
quit;

View solution in original post

2 REPLIES 2
collinelliot
Barite | Level 11

You can calculate the average of a boolean reponse:

 

data have;
    input credit $ class;
datalines;
A         1
B         1
B         1
C         1
A         1
A         2
C         2
C         2
C         2
B         2
;

proc sql;
    SELECT class, 
           mean(credit = 'A') 'A',
           mean(credit = 'B') 'B',
           mean(credit = 'C') 'C'
    FROM have
    GROUP BY class;
quit;

YiqunDai
Fluorite | Level 6
Thank you so much!

##- Please type your reply above this line. Simple formatting, no
attachments. -##

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 863 views
  • 1 like
  • 2 in conversation