Help using Base SAS procedures

Generating Multiple Lags?

Reply
N/A
Posts: 0

Generating Multiple Lags?

Hi:
I want to generate multiple lags(4000+) for many variables ( a, b, c). how is it possible w/o writing thousands of statements:

lag_a_1 = lag1(a);
lag_a_2 = lag2(a);
.
.
.
lag_a_4000= lag4000(a); . . . and so on for other variables.

I tried using Array function in the following but it doesnt work:

DATA xxx.yyy (drop = i);
SET xxx.yyy;

ARRAY Lag_a_{4000};
do i= 1 to 4000;
Lag_a_(i)= lag(i)(a);
end;
run;
any help?
Regards
Moazzam
Frequent Contributor
Posts: 81

Re: Generating Multiple Lags?

Try this...

%macro check;
data X;
set Y;
%do i = 1 %to 4000;
lag_a_&i = lag&i(a);
%end;
run;
%mend check;

%check;
Super Contributor
Super Contributor
Posts: 3,174

Re: Generating Multiple Lags?

It may be useful to explain your interest with sample INPUT and OUTPUT (desired) data example, in case there may be an alternative approach?

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 2 replies
  • 121 views
  • 0 likes
  • 3 in conversation