Hi,
I'm trying to make a simple (not to me) data step action. I need to keep specific rows in my data set. This is an example - my data set looks like this:
Security | Trial | Time | Price |
1 | 1 | 1 | 34 |
1 | 1 | 2 | 34 |
1 | 1 | 4 | 32 |
1 | 1 | 5 | 34 |
1 | 1 | 7 | 33 |
1 | 2 | 2 | 35 |
1 | 2 | 3 | 34 |
1 | 2 | 4 | 36 |
1 | 2 | 6 | 39 |
1 | 2 | 10 | 40 |
2 | 1 | 1 | 80 |
2 | 1 | 3 | 85 |
2 | 1 | 5 | 81 |
2 | 1 | 8 | 76 |
2 | 2 | 2 | 77 |
2 | 2 | 3 | 77 |
2 | 2 | 4 | 77 |
2 | 2 | 5 | 73 |
2 | 2 | 9 | 76 |
2 | 2 | 10 | 78 |
I would like to keep only the highlighted (red) rows. The logic is as follows: by "security" and by "trial" keep the entire row with the highest value of "time"
I appreciate any help on this code.
Thank you
If your data are already in the order shown in your example then the following code like the following could be used:
data want;
set have;
by Security Trial;
if last.trial;
run;
If your data are already in the order shown in your example then the following code like the following could be used:
data want;
set have;
by Security Trial;
if last.trial;
run;
Thank you. Good to know about the "last.***" function in the data step.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.