Hi All,
I am trying to remove some duplicated observations from my data set. The goal is to end with a unique student id and any course they are affiliated with.
For the duplicate observations (same student id and the same course)
This is my first post on here, sorry if I missed anything!
This is how my data looks like right now:
studentid | Grade | final_grade | course |
1 | A | MATH | |
1 | A | MATH | |
1 | C | B | ECON |
1 | B | A | ENG |
1 | B | A | ENG |
1 | C | SCI | |
1 | F | C | SCI |
1 | B | CHEM | |
2 | D | B | ENG |
2 | B | ENG | |
2 | A | CHEM | |
3 | F | C | MATH |
This is what my end goal should look like. Each student having only 1 observation for whatever course they have taken.
studentid | Grade | final_grade | course |
1 | A | MATH | |
1 | C | B | ECON |
1 | B | A | ENG |
1 | F | C | SCI |
1 | B | CHEM | |
2 | D | B | ENG |
2 | A | CHEM | |
3 | F | C | MATH |
I feel like this is a simple answer, but I have scavenged the web with no use. I was originally thinking of copying the grade into the missing fields and simply deleting the duplicate observations? Started running into issues with identifying unique student id and unique course for those students.
Thank you very much!
data have;
input studentid Grade$ final_grade $ course $;
cards;
1 . A MATH
1 . A MATH
1 C B ECON
1 B A ENG
1 B A ENG
1 . C SCI
1 F C SCI
1 . B CHEM
2 D B ENG
2 . B ENG
2 . A CHEM
3 F C MATH
;
proc sort data=have out=_have;
by studentid course;
run;
data want;
update _have(obs=0) _have;
by studentid course ;
run;
data have;
input studentid Grade$ final_grade $ course $;
cards;
1 . A MATH
1 . A MATH
1 C B ECON
1 B A ENG
1 B A ENG
1 . C SCI
1 F C SCI
1 . B CHEM
2 D B ENG
2 . B ENG
2 . A CHEM
3 F C MATH
;
proc sort data=have out=_have;
by studentid course;
run;
data want;
update _have(obs=0) _have;
by studentid course ;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.