BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
tianerhu
Pyrite | Level 9
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;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

tianerhu
Pyrite | Level 9
Thank you for your help.
Tom
Super User Tom
Super User

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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1386 views
  • 0 likes
  • 3 in conversation