Hello everyone,
I need to find the maximum value of a variable looking at all the previous values in the column. i have a dataset that looks the one listed below. i want to create a variable v4 with the maximum value of all the previous values in the column.
DATASET 1
V1 V2 V3
01 AA 02
01 AA 08
01 AA 03
02 BB 24
02 BB 98
02 BB 24
03 CC 11
03 CC 99
03 CC 15
02 DD 54
DATASET 2
V1 V2 V3 v4
01 AA 02 02
01 AA 08 08
01 AA 03 08
02 BB 24 24
02 BB 98 98
02 BB 24 98
03 CC 11 98
03 CC 99 99
03 CC 15 99
02 DD 54 99
data DATASET1; input (V1 V2 V3) ($); cards; 01 AA 02 01 AA 08 01 AA 03 02 BB 24 02 BB 98 02 BB 24 03 CC 11 03 CC 99 03 CC 15 02 DD 54 ; data dataset2; set dataset1; retain v4; v4=max(v3,v4); run;
Art, CEO, AnalystFinder.com
data DATASET1; input (V1 V2 V3) ($); cards; 01 AA 02 01 AA 08 01 AA 03 02 BB 24 02 BB 98 02 BB 24 03 CC 11 03 CC 99 03 CC 15 02 DD 54 ; data dataset2; set dataset1; retain v4; v4=max(v3,v4); run;
Art, CEO, AnalystFinder.com
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.