BookmarkSubscribeRSS Feed
SvenWagner
Fluorite | Level 6

Hi, 

 

I came across with a statement like the following:

 

proc sql;
    create table tmp01 as 
    select    col1
            , col2
            , max(col3, col4) as MaxVar
    from ...
    ;
quit;

So, MAX is used without GROUP BY seemingly as a (row wise) scalar function like within a DATA STEP. Being familiar with "native SQL", I would have expected something like CASE WHEN ELSE END or GREATEST instead of MAX, but the results seem to be the same. Hence, my question is: Can I really use MAX within PROC SQL as it is done within the example? (Correct results also might by coincidence.)

 

Thanks for your help, Sven

1 REPLY 1
Kurt_Bremser
Super User

When you use max() (and other such functions, like min() or avg()) with more than one argument, then it works "horizontally" within the current observation.

With only one column name as parameter, it turns into a summary function that works "vertically" for the group (or the whole dataset).

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1814 views
  • 1 like
  • 2 in conversation