BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
farrukh
Calcite | Level 5

DATA TEST;
INPUT CUST A B C;
CARDS;
1 12 13 14
1 12 13 11
2 12 10 14
2 12 17 14
3 10 16 11
3 10 13 14
4 12 11 14
4 12 11 14
;
RUN;

 

/*the objective is to get aggregated max values per cust, and resulting one column which have max of a,b and c*/

 

/*this codes gives var wise aggregated max values but when i try to find for all a,b,c it gives error*/

PROC SQL;
CREATE TABLE ANA AS
SELECT CUST
,MAX(A) as max_a
,MAX(B) as max_b
,MAX(C) as max_c
from test
group by 1
;quit;

 

PROC SQL;
CREATE TABLE ANA AS
SELECT CUST
,MAX(max_a,max_b,max_c) as max_abc
from test
;quit;

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ

In order to reference new columns in SQL you can use the CALCULATED keyword

 

See sample below:

PROC SQL;
  CREATE TABLE ANA AS
    SELECT CUST
      ,MAX(A) as max_a
      ,MAX(B) as max_b
      ,MAX(C) as max_c
      , max(calculated max_a,calculated max_b,calculated max_c) as maxValue 
    from test
      group by 1
  ;
quit;

But one could run another query on the ANA table to create the max column

 

Bruno

View solution in original post

2 REPLIES 2
BrunoMueller
SAS Super FREQ

In order to reference new columns in SQL you can use the CALCULATED keyword

 

See sample below:

PROC SQL;
  CREATE TABLE ANA AS
    SELECT CUST
      ,MAX(A) as max_a
      ,MAX(B) as max_b
      ,MAX(C) as max_c
      , max(calculated max_a,calculated max_b,calculated max_c) as maxValue 
    from test
      group by 1
  ;
quit;

But one could run another query on the ANA table to create the max column

 

Bruno

Reeza
Super User

Select cust, max(a) as maxA, max(b) as maxB, max(C) as MaxC, max( calculated maxA, calculated maxB, calculated maxC) as overallMax

from have

group by cust;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 3393 views
  • 2 likes
  • 3 in conversation