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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.