I have this dataset:
data x;
infile datalines;
input id r2d2 price;
datalines;
15 12 10
15 12 14
22 17 12
88 16 23
22 17 10
22 15 34
88 15 95
;;
run;What I'd like to do is - for observations that have the same value for r2d2, I want to output only the observation with the lowest price. How would I go about doing this
An SQL solution
--- UNTESTED CODE ----
proc sql;
create table new as select * from x group by r2d2 having price=min(price);
quit;
Sort the data so that the smallest value is first and then use SAS FIRST logic to keep the record.
An SQL solution
--- UNTESTED CODE ----
proc sql;
create table new as select * from x group by r2d2 having price=min(price);
quit;
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 save with the early bird rate—just $795!
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.