Thanks. I will try the code and let you know. I did not read the documentation at this moment. Will you please send me the link?
Hi again, I need to calculate ca at time t+1 as well. So, ca values at t-1, t and t+1.
I should have guessed. :smileyplain: I should have asked before now. Do you have SAS/ETS software? Type in PROC EXPAND; RUN; and see what your messages are. If that works consult the documentation. It does lags leads and a lot more.
This sure sounds like a FIFO problem. What do you need to do with the lagged data once you get them?
The following keeps the current and up to the last three values for each variable and then calculates the average of the up to 4 values:
data want (drop=counter);
set have;
by companyISIN notsorted;
retain counter .;
array ca_stack {0:3};
array cl_stack {0:3};
array stdebt_stack {0:3};
retain ca_stack cl_stack stdebt_stack;
if first.companyISIN then do;
call missing(of ca_stack{*});
call missing(of cl_stack{*});
call missing(of stdebt_stack{*});
counter=0;
end;
counter+1;
ca_stack{mod(counter,4)} = ca;
cl_stack{mod(counter,4)} = cl;
stdebt_stack{mod(counter,4)} = stdebt;
if year not in (2003,2013) then do;
ca_avg = mean(of ca_stack{*});
cl_avg = mean(of cl_stack{*});
stdebt_avg = mean(of stdebt_stack{*});
output;
end;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: