BookmarkSubscribeRSS Feed
PCrider
Calcite | Level 5
I have data containing student IDs, classes, grades, semesters, etc. I want to find all the times that a student repeated a class; so the same student ID and the same course number but not necessarily the same grade or semester. i want to keep only the last (by date) recorded grade for that class but at the same time i want to count the number of repeat classes.
here is some data:

ID@semester(1st number=semester number/last 2 numbers=year)
@class@credits@grade recieved

04F1M@191@C S 131@2.0@UW@
04F1M@187 @CL CV 241@3.0@C@
04F1M@587@ECON 110@3.0@D-@
04F1M@590@ECON 110@3.0@B@
04F1M@586@ENGL 115@4.0@B@
04F1M@590@ENGL 391@3.0@C-@

thanks
2 REPLIES 2
art297
Opal | Level 21
You might be able to do what you want with something like:


data have;
infile cards delimiter="@";
informat class $10.;
format date date9.;
input ID $ semester $ class credits grade_recieved $;
date=mdy(substr(semester,1,1),1,substr(semester,2,2));
cards;
04F1M@191@C S 131@2.0@UW
04F1M@187 @CL CV 241@3.0@C
04F1M@587@ECON 110@3.0@D-
04F1M@590@ECON 110@3.0@B
04F1M@586@ENGL 115@4.0@B
04F1M@590@ENGL 391@3.0@C-
;

proc sort data=have;
by ID class date;
run;

data want;
set have;
by id class;
if first.class then count=1;
else count+1;
if last.class then output;
run;

HTH,
Art
DBailey
Lapis Lazuli | Level 10
How about:

data Classes_Taken;
infile cards delimiter="@";
informat class $10.;
format date date9.;
input ID $ semester $ class credits grade_recieved $;
class_date=mdy(substr(semester,1,1),1,substr(semester,2,2));
cards;
04F1M@191@C S 131@2.0@UW
04F1M@187 @CL CV 241@3.0@C
04F1M@587@ECON 110@3.0@D-
04F1M@590@ECON 110@3.0@B
04F1M@586@ENGL 115@4.0@B
04F1M@590@ENGL 391@3.0@C-
;
run;

proc sql;
create table retakes as
select
id,
class,
count(*) as times_taken,
max(class_date) Last_date
from work.classes_taken
group by id, class
having count(*)>1;

create table last_retake as
select
t2.*,
t1.times_taken
from work.retakes t1 inner join work.classes_taken t2
on t1.id=t2.id and t1.class=t2.class and t1.last_date=t2.class_date;
quit;

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
  • 684 views
  • 0 likes
  • 3 in conversation