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

I need to do a calculation for each level of detail in proc sql: count number of courses for each ID, and sum number of Failed for each ID. Here is a sample of data. Notice that COURSE is not a numeric variable, so I cannot use proc summary or proc means. Does anyone have a better idea? Thanks!

 

IDCOURSEFailed
1NGR-78921
1NGR-79450
1NGR-79740
2LIS-59730
2LIS-59421
2NGR-62070
2TTE-66551
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

I don't know what to do with the hypothetical case where a given id failed the same course twice. This counts it as two failures:

 

proc sql;
select 
	id,
	count(distinct course) as nbCourses,
	sum(failed) as nbFailed
from myData
group by ID;
quit;
PG

View solution in original post

4 REPLIES 4
PGStats
Opal | Level 21

I don't know what to do with the hypothetical case where a given id failed the same course twice. This counts it as two failures:

 

proc sql;
select 
	id,
	count(distinct course) as nbCourses,
	sum(failed) as nbFailed
from myData
group by ID;
quit;
PG
xliu1
Quartz | Level 8

Thanks. This code works perfectly.

Kurt_Bremser
Super User

You can use proc summary with your data:

data have;
input id $ course $ failed;
datalines;
1 NGR-7892  1
1 NGR-7945  0
1 NGR-7974  0
2 LIS-5973  0
2 LIS-5942  1
2 NGR-6207  0
2 TTE-6655  1
;

proc summary data=have nway;
var failed;
class id;
output
  out=want (drop=_type_ rename=(_freq_=count))
  sum(failed)=
;
run;
xliu1
Quartz | Level 8

Thank you. The code you shared also works!

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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
  • 4 replies
  • 496 views
  • 1 like
  • 3 in conversation