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;
3762722 | 132066 | 130260 | 05JUL2017 | Alive | 29JUN2017 | 29JUN2017 | 09JUL2018 | . | Alive | . | 0 | 2 |
3762722 | 132066 | 130260 | 05JUL2017 | Alive | 29JUN2017 | 29JUN2017 | 08AUG2017 | . | Alive | . | 0 | 2 |
3762722 | 132066 | 130265 | 05JUL2017 | Alive | 30JUN2017 | 30JUN2017 | 09JUL2018 | . | Alive | . | 0 | 2 |
3762722 | 132066 | 130265 | 05JUL2017 | Alive | 30JUN2017 | 30JUN2017 | 08AUG2017 | . | Alive | . | 0 | 2 |
3762722 | 64600 | 63607 | 17JAN2016 | Alive | 15JAN2016 | 15JAN2016 | 23JAN2017 | . | Alive | . | 0 | 2 |
3762722 | 64600 | 63607 | 17JAN2016 | Alive | 15JAN2016 | 15JAN2016 | 29FEB2016 | . | Alive | . | 0 | 2 |
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.
Hello!
Based on what you said, it sounds exactly what I'm looking for. Thanks for the clarification!
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.
Ready to level-up your skills? Choose your own adventure.