Solved
Contributor
Posts: 62

# return volatility-std deviation of return for past 1 year

I wish to cacluate std deviation of returns for the past one year for year 2002.

i have used proc means

proc means data=rtnvol.rtnvol std;

by permno;

run;

it give me an output listing by permno its std deviation.

But I need the result to be generated in a SAS file-listing std deviation for each firm so that i can merge the data with other data for further processing.

Condition: company should have at least 200 observations to obtain the std deviation, can you build in this in the program?

Also: if I need to calculate the std deviation of returns for each firm for financial year for 2003-2010, do i repeat the steps given for each year, or is that a faster manner?

Pls help!!

Accepted Solutions
Solution
‎05-18-2012 11:25 AM
Super User
Posts: 13,542

## Re: return volatility-std deviation of return for past 1 year

You can use a CLASS statement to avoid a requirement to sort; If you only want the output data set and no print output use PROC SUMMARY as it doesn't create print output by default and the syntax is basically the same as PROC MEANS.

Proc summary data=rtnvol.rtnvol nway;

class permno;

var <list of variables you want summarized>;

/* direct output to data set*/

output out=want  std= n= /autoname autolabel; /* this creates a separate variable for the output for each statistic requested on var line and names them var_StdDev and Var_n.*/

run;

You could then filter any reports from the output data set to include the variables where the _N indicates you have enough records.

All Replies
Posts: 3,167

## Re: return volatility-std deviation of return for past 1 year

If I understand you correctly, and the 'permno' in 'by' statement is the company id, then the following example may give you  a hint:

proc sort data=sashelp.class out=have;

by sex;

run;

proc means data=have;

by sex ;

output std= out=want (drop=_;

run;

proc print;run;

Good Luck,

Haikuo

Solution
‎05-18-2012 11:25 AM
Super User
Posts: 13,542

## Re: return volatility-std deviation of return for past 1 year

You can use a CLASS statement to avoid a requirement to sort; If you only want the output data set and no print output use PROC SUMMARY as it doesn't create print output by default and the syntax is basically the same as PROC MEANS.

Proc summary data=rtnvol.rtnvol nway;

class permno;

var <list of variables you want summarized>;

/* direct output to data set*/

output out=want  std= n= /autoname autolabel; /* this creates a separate variable for the output for each statistic requested on var line and names them var_StdDev and Var_n.*/

run;

You could then filter any reports from the output data set to include the variables where the _N indicates you have enough records.

Contributor
Posts: 62

## Re: return volatility-std deviation of return for past 1 year

Dear ballardw,

I have used this programming codes:

Proc summary data=rtnvol.rtnvol2 nway;

class permno fyear;

var ret;

output out=rtnvol.rtn_std2002_03  std= n= /autoname autolabel;

run;

The result generated contain one column with variable _TYPE_=3, what does this mean?

(Note : if i use this prog code

Proc summary data=rtnvol.rtnvol2 nway;

class permno;  /*class fyear not included*/

var ret;

output out=want  std= n= /autoname autolabel;

run;

then the _TYPE_=1)

Super User
Posts: 10,778

## Re: return volatility-std deviation of return for past 1 year

en. SQL is a good tool for your problem.

Assuming the table is under c:\ .

```libname x v9 'c:\';
proc sql;
create table want as
select fyear,conm,std(ret) as return_std
from x.Rtnvol
group by fyear,conm ;
quit;

```

Ksharp

🔒 This topic is solved and locked.