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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 917 views
  • 0 likes
  • 3 in conversation