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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 182 views
  • 0 likes
  • 2 in conversation