First I provide code where the 6 month is hard-coded, and then I modify the code to allow for 10 month or 12 month or whatever.
/* UNTESTED CODE */
data want;
set have;
array v var1-var276;
array pctchg pctchg1-pctchg276;
do i=1 to dim(v);
pctchg(i)=100*(v(i)-lag5(v(i)))/lag5(v(i)); /* 6 months ago is found via lag5 */
end;
run;
Example code where you can change the lag
/* UNTESTED CODE */
%let lag_desired=10;
%let lag_to_use=%eval(&lag_desired-1);
data want;
set have;
array v var1-var276;
array pctchg pctchg1-pctchg276;
do i=1 to dim(v);
pctchg(i)=100*(v(i)-lag&lag_to_use(v(i)))/lag&lag_to_use(v(i));
end;
run;
Its not exactly clear to me how your data is arranged. Is it something like this
var1 var2 data for q12010 data for q12010 data for q22010 data for q22010 data for q32010 data for q32010 ... ...
If yes, then we can help you create a program. If no, then we need to know the arrangement of the data before we can be of any help, in this case SHOW US a portion of the data (we don't need all 300 variables, but 2 or 3 would be great).
Thanks, now please walk us through one example of performing the calculation of "lag of 6 Quater percentage change", using the above data that you provided.
First I provide code where the 6 month is hard-coded, and then I modify the code to allow for 10 month or 12 month or whatever.
/* UNTESTED CODE */
data want;
set have;
array v var1-var276;
array pctchg pctchg1-pctchg276;
do i=1 to dim(v);
pctchg(i)=100*(v(i)-lag5(v(i)))/lag5(v(i)); /* 6 months ago is found via lag5 */
end;
run;
Example code where you can change the lag
/* UNTESTED CODE */
%let lag_desired=10;
%let lag_to_use=%eval(&lag_desired-1);
data want;
set have;
array v var1-var276;
array pctchg pctchg1-pctchg276;
do i=1 to dim(v);
pctchg(i)=100*(v(i)-lag&lag_to_use(v(i)))/lag&lag_to_use(v(i));
end;
run;
If I am understanding you properly
data want;
set have;
array v var1-var276;
array pctchg pctchg1-pctchg276;
array lagpctchg lagpctchg1-lagpctchg276;
do i=1 to dim(v);
pctchg(i)=100*(v(i)-lag5(v(i)))/lag5(v(i)); /* 6 months ago is found via lag5 */
lagpctchg(i)=lag(pctchg(i));
end;
drop i;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.