@Irenelee wrote:
How may SAS code create a new Column named “H” which is a firm’s historical high price? (every line we have a firm’s id PERMNO, date, close price) vice versa “L”
How may SAS code create a new Column named “HH” which HH=LAG(H), BUT FIRST YEAR'S PERMNO’s daily HH=INFINITE. (the price have to exist more than one year, for example 1963/1/1’s historical high price have to be have price exsit from 1962/1/1. Because I want to make sure at least 1 year of available daily price data, which is required to be defined historical high stock price may be compared with the 52-week period range.
To create the highest value every seen for a "firm" just make a NEW variable and RETAIN it. Change the value when the price goes up.
data want;
set have;
by firm;
retain H L ;
h= max(h,price);
l = min(l,price);
if first.firm then do;
h=price; l=price;
end;
run;
The second description is too confusing to program from. If the point is to remember WHEN the H and L price occurred then remember that also. In which case the programming gets a little more complicated.
data want;
set have;
by firm;
retain H L H_date L_date;
format h_date l_date date9.;
if first.firm then do;
h=price; h_date=date;
l=price; l_date=date;
end;
else do ;
if h<price then do; h=price; h_date=date; end;
if l > price then do; l=price; l_date=date; run;
end;
run;
You can now test on any date how long it has been since the most recent high occured.
Whether or not that is what you are looking for I have NO idea.
... View more