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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1256 views
  • 0 likes
  • 3 in conversation