BookmarkSubscribeRSS Feed
Fer_
Fluorite | Level 6

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. 

3 REPLIES 3
mkeintz
PROC Star

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;

 

 

 

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Fer_
Fluorite | Level 6

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. 

 

mkeintz
PROC Star

@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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 175 views
  • 0 likes
  • 2 in conversation