BookmarkSubscribeRSS Feed
corkee
Calcite | Level 5

Hello,

 

I'm trying to select the first observation based on multiple BY values, using the first or last modifier. The data below are already sorted, and I really want to keep the rows that are in bold (the first column is patientID, second is episodekey, and third is visitkey). Essentially, some patientID's have multiple VISITKEY's linked to the same EPISODEKEY. For these subjects, I want to keep the unique episodes, after sorting the data appropriately. 

 

This is the code I've used to sort the data:

 

proc sort data=fix2; 
by ncdrpatientid episodekey visitkey descending died_yn descending f_assessmentdate descending dcdate descending tvtprocedurestopdate;
run;

I'm not sure if this works. Can anyone provide some guidance?

data fix_final;
	set fix2;
	by ncdrpatientid episodekey visitkey descending died_yn descending f_assessmentdate descending dcdate descending tvtprocedurestopdate;
	if first.episodekey;
run;
376272213206613026005JUL2017Alive29JUN201729JUN201709JUL2018.Alive.02
376272213206613026005JUL2017Alive29JUN201729JUN201708AUG2017.Alive.02
376272213206613026505JUL2017Alive30JUN201730JUN201709JUL2018.Alive.02
376272213206613026505JUL2017Alive30JUN201730JUN201708AUG2017.Alive.02
3762722646006360717JAN2016Alive15JAN201615JAN201623JAN2017.Alive.02
3762722646006360717JAN2016Alive15JAN201615JAN201629FEB2016.Alive.02
2 REPLIES 2
ballardw
Super User

It depends on what you mean by "works".

 

The shown FIRST. value will select the first record for each level of the Episodekey variable within each patient id.

corkee
Calcite | Level 5

Hello!

 

Based on what you said, it sounds exactly what I'm looking for. Thanks for the clarification!

 

 

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
  • 2 replies
  • 649 views
  • 0 likes
  • 2 in conversation