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;
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
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
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.