Is this all you want?
data have;
attrib date length=4 format=date9.;
do date = '1jan2015'd to '31dec2015'd;
price = int(ranuni(225465114) * 30) + 95;
output;
end;
run;
data want;
set have;
retain max_increase 0;
max_increase = max(max_increase, price / lag6(price));
format max_increase 6.2;
run;
Not sure if I correctly understand what you are trying to get, but I think that the following comes close:
data have;
attrib date length=8 format=date9.;
do date = '1jan2015'd to '31dec2015'd;
price = int(ranuni(123) * 30) + 95;
output;
end;
run;
data need (keep=date pric max_increase);
set have;
retain stack0-stack6;
array stack(0:6) stack0-stack6;
stack(mod(_n_,7))=price;
x=mod(_n_,7);
max_increase=0;
do i=2 to 6, 0;
if i eq 0 then j=6;
else j=i-1;
max_increase=max(stack(i)/stack(j),max_increase);
end;
run;
proc sql;
select max(max_increase)
from need
;
quit;
Art, CEO, AnalystFinder.com
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.