BookmarkSubscribeRSS Feed
ddeb
Calcite | Level 5
I have data of the form:

ID Sales_JAN Sales_FEB Sales_MAR etc....

I know that I can get the maximum sales value for each ID as:
MAX_SALES = MAX (OF SALES:);

I also want to know which month the maximum sales happened in (the variable name which corresponds to the maximum value). I cannot figure out how to do this efficiently. I'm sure SAS has a way of doing this (it has a way of doing most things). If JAN and FEB had the same sales and they were the MAX value, how are ties handled?
2 REPLIES 2
data_null__
Jade | Level 19
WHICHN Function

--------------------------------------------------------------------------------

Searches for a numeric value that is equal to the first argument, and returns the index of the first matching value.
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Ddeb,

You can add to you datastep writing MAX_SALES into a macro variable like this:

call SUMPUTX('Max',MAX_SALES);

and then in a separate datastep:

array{*} S sales:;
do i=1 to hbound{S};
if s[i]=&Max then Max_month=i;
end;

get month number for maximum sales.

Sincerely,
SPR

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 680 views
  • 0 likes
  • 3 in conversation