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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.