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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 1925 views
  • 1 like
  • 2 in conversation