BookmarkSubscribeRSS Feed
Adnan_Razaq
Calcite | Level 5

Hi,

 

I have

 

account   date   arrears 

1              Jan      0         

1              Feb      1             

1              Mar      0             

1              Apr       2            

2              Jan       0             

2              Feb       1             

2              Mar       2             

           

 

I need

 

account   date   arrears  max_arrears

1              Jan      0              0

1              Feb      1              1

1              Mar      0              1

1              Apr       2              2

2              Jan       0              0

2              Feb       1              1

2              Mar       2              2

           

Any coding suggestions please?

 

Thanks in advance

 

Adnan

4 REPLIES 4
LinusH
Tourmaline | Level 20

Not sure if you request matches your subject...

But, use RETAIN within a data step.

Data never sleeps
Reeza
Super User

There is no max or min that I see, only keeping the previous value. Can you clarify your requirements? 

 

It may be as a simple as:

 

if first.account then max_value =arrears;

else max_value = max(max_value, arrears);

Adnan_Razaq
Calcite | Level 5

Apologies for the confusion.

 

What I require is  the max arrears value by account and date.

 

Thanks

 

Adnan

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Post test data in the form of a datastep.

 

Just a guess:

data want;
  set have;
  retain max_arrears;
  by account;
  if first.account then max_arrears=0;
  if arrears > max_arrears then max_arrears=arrears;
run;

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
  • 4 replies
  • 769 views
  • 0 likes
  • 4 in conversation