Hello,
I'd like to calculate rolling cumulative 4 quarters of earnings (for different cusip).
Currently this is the code I use:
%macro mom(datain=);
%do iter=1 %to 3;
proc sort data=&datain; by cusip line; run;
data &datain; set &datain; by cusip;
if &iter<=1 then C2E=C2E+lag(epspiq);
if &iter<=2 then C3E=C3E+lag&iter(epspiq);
if &iter<=3 then C4E=C4E+lag&iter(epspiq);
run;
%end;
%mend;
%mom(datain=com);
It works well for the first cusip, however since the second cusip, it takes the lag of earnings from the previous cusip, which is not correct.
Please kindly advise.
I'm fine to use other procedures and not only macro procedure.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.