Have: | |||
ID | v1 | v2 | v3 |
1 | -3 | a | a |
1 | -2 | b | b |
1 | -1 | c | b |
1 | 1 | d | b |
2 | -20 | a | a |
2 | -6 | b | b |
2 | -3 | c | b |
2 | -2 | d | b |
3 | 1 | a | a |
want: | |||
ID | v1 | v2 | v3 |
1 | 1 | d | b |
2 | -2 | d | b |
3 | 1 | a | a |
I am trying to find one unique observation per id. v1 ranges from 1 to -20. I am trying to output the highest and unique value possible for v1.
Very easy.
proc sort data=have;
by id v1;
run;
data want;
set have;
by id;
if last.id;
run;
Is the ID and v1 combination unique?
If so, use SQL with group by ID having max(v1) = v1.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.