BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

An SQL solution

 

--- UNTESTED CODE ----

proc sql;
    create table new as select * from x group by r2d2 having price=min(price);
quit;
--
Paige Miller

View solution in original post

2 REPLIES 2
Reeza
Super User

Sort the data so that the smallest value is first and then use SAS FIRST logic to keep the record. 

PaigeMiller
Diamond | Level 26

An SQL solution

 

--- UNTESTED CODE ----

proc sql;
    create table new as select * from x group by r2d2 having price=min(price);
quit;
--
Paige Miller

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 740 views
  • 1 like
  • 3 in conversation