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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21
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

 

View solution in original post

1 REPLY 1
art297
Opal | Level 21
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

 

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
  • 1 reply
  • 10705 views
  • 3 likes
  • 2 in conversation