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

Hello,

 

I'm sure this is fairly straight forward but I just can't get my head around how.

 

I've got a table with a base value for the first record in a category.  All other rows within this category have an adjustment rate.  I want to work out the new value based upon this adjustment rate.  But it's sequential, so row 1 value * row 2 rate = row 2 value, row 2 value * row 3 rate = row 3 value etc.  It's not the easiest thing to articulate, so here's an example.

 

Starting table

ClassMonthAdjustment_RateBase_Value
Category 1Jan-18 10.00
Category 1Feb-180.96 
Category 1Mar-180.99 
Category 1Apr-181.02 
Category 1May-181.05 
Category 2Jan-18 15.00
Category 2Feb-180.94 
Category 2Mar-181.00 
Category 2Apr-181.03 
Category 2May-181.03 

 

This is what I want in the end (I'd subsequently drop Base_Value)

ClassMonthAdjustment_RateBase_ValueNew_Value
Category 1Jan-18 10.0010.00
Category 1Feb-180.96 9.60
Category 1Mar-180.99 9.50
Category 1Apr-181.02 9.69
Category 1May-181.05 10.18
Category 2Jan-18 15.0015.00
Category 2Feb-180.94 14.10
Category 2Mar-181.00 14.10
Category 2Apr-181.03 14.52
Category 2May-181.03 14.96

 

I'm assuming I need to use a lag function, e.g. lag Base_Value, but on observation 2 I need to lag the new value.

 

Thanks in advance!

 

Edit: Fixing typos.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

No need for lag(), but for retain:

data want;
set have;
by class;
retain new_value;
if first.class
then new_value = base_value;
else new_value = new_value * adjustment_rate;
run;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

No need for lag(), but for retain:

data want;
set have;
by class;
retain new_value;
if first.class
then new_value = base_value;
else new_value = new_value * adjustment_rate;
run;
satkin2
Calcite | Level 5
Perfect. Thank you very much.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1033 views
  • 0 likes
  • 2 in conversation