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

I have a dataset of test scores. My variables are (test taker’s) ID_no, test date, test score, and test type (online or in person).

Some people took the test online and in person, and therefore, are in the dataset more than once.

I’d like to make a new dataset with only those whose ID_no shows up more than once. And then with that dataset, I’d like to clean it to only include the most recent test date for each ID_no.

 

I'm not super familiar with SQL and want to develop this skill. What kind of procedure would I need to use to achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Assuming that the people who took the test online and in person did not do this both on the same day, this should work

 

proc sql;
     create table want as select * from have
     group by ID_no
     having test_date=max(test_date);
quit;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Assuming that the people who took the test online and in person did not do this both on the same day, this should work

 

proc sql;
     create table want as select * from have
     group by ID_no
     having test_date=max(test_date);
quit;
--
Paige Miller
SAS_learneromg
Fluorite | Level 6
Yes, that's exactly what I needed to. Thank you!
acordes
Rhodochrosite | Level 12
Written on my smartphone here comes a possible solution that you could try.
Proc Sort data=have;
By id_no test_date;
Run;

Data want;
Set have;
By id_no test_date;
If first.id_no <> last.id_no;
Call missing(test_score);
Run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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