BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
NickR
Quartz | Level 8
Try this...

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

%check;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.

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
  • 2 replies
  • 943 views
  • 0 likes
  • 3 in conversation