BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mei
Calcite | Level 5 mei
Calcite | Level 5

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!!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

4 REPLIES 4
Haikuo
Onyx | Level 15

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

ballardw
Super User

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.

mei
Calcite | Level 5 mei
Calcite | Level 5

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)

Ksharp
Super User

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 2806 views
  • 0 likes
  • 4 in conversation