Hello Everyone.
I want to calculate standard deviation of the firm's daily returns during a given year. I have permno as identifier for each firm and daily data for stock return. Such as below.
Permno date ret
10000 10/03/2002 0.005
10000 10/06/2002 0.0051
10002 12/06/2002 0.007
and so on.
Could you please help me to calculate standard deviation of the firm's daily returns during a given year?
Thanks in advance.
If you want std of returns for each permno for the same year, then, assuming data are sorted by PERMNO:
proc summary data=have ;
by permno ;
where '01jan2022'd <= date <= '31dec2022'd;
var ret;
output out=want (drop=_:) std=retstd;
run;
If you want it for each year in a series of multiple years, then, if data are sorted by permno year:
data need / view=need;
set have;
year=year(date);
run;
proc summary data=need ;
by permno year;
var ret;
output out=want (drop=_:) std=retstd;
run;
Thanks for your reply.
I want to get yearly std for each firm (permno) which has daily stock return. Which means for each firm in each year, I need to have one std at the end.
@Fer_ wrote:
Thanks for your reply.
I want to get yearly std for each firm (permno) which has daily stock return. Which means for each firm in each year, I need to have one std at the end.
That is what my second code block provides. Test it on a small sample of data to see for yourself.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.