SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

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

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

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 workSmiley Sad

NumRevDate
345454Jan-01-2013
4354353Feb-01-2013
725425Mar-01-2013
3254235Jan-01-2014
8Feb-01-2014
9Mar-01-2014
12Jan-01-2015
45Feb-01-2015lag

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

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

Posted in reply to loving_apples

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.

View solution in original post


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

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

Posted in reply to loving_apples

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

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

Posted in reply to Astounding

Great thanks Astounding, but what if I need lag4 instead of lag2, what I shall change the code?

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 296 views
  • 1 like
  • 2 in conversation