Help using Base SAS procedures

can you sum a lag?

Reply
N/A
Posts: 0

can you sum a lag?

I'm trying to do the following

sum(x1*lag(x1), x2*sum(x2),,);

x1 etc are macro variables actually &var&&z.


I'm thinking that I need some way to pass the lagged value into the sum function. All my tests seem to indicate just saying sum(lag(x1)) does not pass a value
Respected Advisor
Posts: 4,173

Re: can you sum a lag?

Posted in reply to deleted_user
It would be easier you would provide us your code.

But may be the following gives you the hint you need.

data have;
do x1=1 to 5;
x2=10*x1;
output;
end;
run;

data want;
set have;
retain x2sum;
x2sum=sum(x2sum,x2);
sumvar=sum(x1*lag(x1), x2*x2sum);
put x1= x2= x2sum= sumvar=;
run;
Ask a Question
Discussion stats
  • 1 reply
  • 129 views
  • 0 likes
  • 2 in conversation