Hello @doudouh ,
Here is my table per specifications:
... And here is what I did:
( IF ( RelativePeriod(_Sum_, 'number'n, _IgnoreAllTimeFrameFilters_, 'Date'n, _Inferred_, 0, _Full_, {Date}) NotMissing ) RETURN RelativePeriod(_Sum_, 'number'n, _IgnoreAllTimeFrameFilters_, 'Date'n, _Inferred_, 0, _Full_, {Date}) ELSE 0 ) + (IF ( RelativePeriod(_Sum_, 'number'n, _IgnoreAllTimeFrameFilters_, 'Date'n, _Inferred_, -1, _Full_, {Date}) NotMissing ) RETURN RelativePeriod(_Sum_, 'number'n, _IgnoreAllTimeFrameFilters_, 'Date'n, _Inferred_, -1, _Full_, {Date}) ELSE 0 ) + (IF ( RelativePeriod(_Sum_, 'number'n, _IgnoreAllTimeFrameFilters_, 'Date'n, _Inferred_, -2, _Full_, {Date}) NotMissing ) RETURN RelativePeriod(_Sum_, 'number'n, _IgnoreAllTimeFrameFilters_, 'Date'n, _Inferred_, -2, _Full_, {Date}) ELSE 0 )
Let me know if you need more detailed helped.
Best regards,
Petri Roine
Hi Petri Roine,
Thanks for your answer.
I forgot to specify that I want this manipulation in SAS Base (not in SAS VA).
Thanks
Ad
Apologies. I was probably working with VA at that time and just used it without thinking too much. Here's a code snippet to solve your problem in BASE SAS. I'm using SAS Lag function which makes solving this very straightforward.
/* Sort to proper order. My example file was in wrong order */
proc sort data=sum_cumulative;
by date;
run;
/* Input file: sum_cumulative. Output file: newdata */
data newdata;
set sum_cumulative;
number = number + lag1(number) + lag2(number);
run;
I hope this helps!
Best regards,
Petri
Thank you very much.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.