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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.