BookmarkSubscribeRSS Feed
SAS_taozi
Calcite | Level 5

I have a dataset below and would like to how to get the minimum price each month. The product could only be possibly priced in one of the months. So if the product has been priced in June, I would like to get the minimum price by product ID in June; if the product has been priced in July, then the minimum price by product ID in July should be attained.

ID          June         July

1            25            .

1            24            .

1            26            .

2            .               34

2            .               37

3            .               56

 

The desired the dataset I want to generate would be:

ID          June         July

1            24            .

2            .               34

3            .               56

 

I tried to do two if ... then do; group by ID; end; BUT the error shows up like " More than one BY statement specified for a SET, MERGE, UPDATE, or MODIFY statement." I am wondering how to solve this... Many thanks for anyone replies!

 

1 REPLY 1
Tom
Super User Tom
Super User

If you have variables named JUNE and JULY just take the MIN of them by ID.

proc summary data=have;
  by id;
  var june july;
   output out=want min= ;
run;

If that is not how your data is actually structured then show a more representative example of the data you actually have.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 528 views
  • 0 likes
  • 2 in conversation