## How to generate Time Series Date based on this variable previous numbers

Solved
Occasional Contributor
Posts: 6

# How to generate Time Series Date based on this variable previous numbers

Good afternoon,

I may have a problem to generate new data.   As we can see that after Jan-01-2014, Rev is 0. And I would like to fill Rev after Jan-01-2014 by calculating: Rev=lag2(Rev)*Exp(Num). However, there is no data for Rev after Jan-01-2014, so SAS cannot calculate Rev based on the lagged Rev. I tried Retain but it didn't work

 Num Rev Date 3 45454 Jan-01-2013 4 354353 Feb-01-2013 7 25425 Mar-01-2013 3 254235 Jan-01-2014 8 Feb-01-2014 9 Mar-01-2014 12 Jan-01-2015 45 Feb-01-2015lag

Accepted Solutions
Solution
‎03-16-2014 10:21 PM
Super User
Posts: 6,622

## Re: How to generate Time Series Date based on this variable previous numbers

Yes, that would be a problem.  LAG works on the original values when the LAG function is invoked, rather than the subsequent values after manipulating the data.

Here's a workaround, creating your own stream of values that mimics what the LAG function would do but after manipulating the data.

data want;

back2 = back1;

back1 = rev;

retain back1;

set have;

if rev=. then rev=back2 * exp(num);

* optionally, once the program is working, drop back1 back2;

run;

Good luck.

All Replies
Solution
‎03-16-2014 10:21 PM
Super User
Posts: 6,622

## Re: How to generate Time Series Date based on this variable previous numbers

Yes, that would be a problem.  LAG works on the original values when the LAG function is invoked, rather than the subsequent values after manipulating the data.

Here's a workaround, creating your own stream of values that mimics what the LAG function would do but after manipulating the data.

data want;

back2 = back1;

back1 = rev;

retain back1;

set have;

if rev=. then rev=back2 * exp(num);

* optionally, once the program is working, drop back1 back2;

run;

Good luck.

Occasional Contributor
Posts: 6