- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi guys,
suppose to have the following:
ID Year
A 2018
A 2018
A 2020
A 2020
A 2021
B 2020
B 2020
....... .............
Is there a way to get the following?
ID Year
A 2018
B 2020
....... .............
Meaning: if ID has more than one year like "A" then take the most ancient and take it one time; if ID has more records of the same year, then take the ID and the relative year one time.
Thank you in advance
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can achieve this with a simple DATA step.
You'll first need to sort the data by ID and YEAR.
proc sort data=have;
by id year;
run;
Then use a DATA step with a BY statement, keeping only the first occurence of each ID. Since the data is sorted by ID and YEAR, you'll automatically keep the earliest occurence of each ID.
data want;
set have;
by id;
if first.id;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can achieve this with a simple DATA step.
You'll first need to sort the data by ID and YEAR.
proc sort data=have;
by id year;
run;
Then use a DATA step with a BY statement, keeping only the first occurence of each ID. Since the data is sorted by ID and YEAR, you'll automatically keep the earliest occurence of each ID.
data want;
set have;
by id;
if first.id;
run;