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

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)

  • if there is a value in the grade variable it should be kept
  • if there is no value in the grade variable it should be represented as missing

This is my first post on here, sorry if I missed anything!

 

This is how my data looks like right now:

 

studentidGradefinal_gradecourse
1 AMATH
1 AMATH
1CBECON
1BAENG
1BAENG
1 CSCI
1FCSCI
1 BCHEM
2DBENG
2 BENG
2 ACHEM
3FCMATH

 

This is what my end goal should look like. Each student having only 1 observation for whatever course they have taken. 

 

studentidGradefinal_gradecourse
1 AMATH
1CBECON
1BAENG
1FCSCI
1 BCHEM
2DBENG
2 ACHEM
3FCMATH

 

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!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20
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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 1454 views
  • 1 like
  • 2 in conversation