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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.