data work.numbers;
infile datalines;
input T;
datalines;
6
7
8
;
proc print data = work.numbers noobs;
run;
title 'sum of lag';
data work.move;
set work.numbers;
if _N_= 3 then total=sum(T,lag1(T),lag2(T));
run;
proc print data = work.move noobs;
run;
Because you commit the #1 capital sin of LAG: using the function conditionally. The LAG functions will only populate their queue when actually called, so you put nothing into the queue until the third observation, where the result is still missing.
Because you commit the #1 capital sin of LAG: using the function conditionally. The LAG functions will only populate their queue when actually called, so you put nothing into the queue until the third observation, where the result is still missing.
Looks like you want this program instead.
data work.numbers;
input T;
datalines;
6
7
8
;
data work.move;
set work.numbers;
total=sum(T,lag1(T),lag2(T));
if _N_< 3 then call missing(total);
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.