1
votes

I am working on a research project that requires me to run a linear regression on the stock returns (of thousands of companies) against the market return for every single day between 1993 to 2014.

The data would be similar to (This is dummy data):

| Ticker   | Time     | Stock Return | Market Return |
|----------|----------|--------------|---------------|
| Facebook | 12:00:01 | 1%           | 1.5%          |
| Facebook | 12:00:02 | 1.5%         | 2%            |
| ...      |          |              |               |
| Apple    | 12:00:01 | -0.5%        | 1.5%          |
| Apple    | 12:00:03 | -0.3%        | 2%            |

The data volume is pretty huge. There are around 1.5 G of data for each day. There are 21 years of those data that I need to analyze and run regression on.

Regression formula is something similar to

Stock_Return = beta * Market_Return + alpha 

where beta and alpha are two coefficients we are estimating. The coefficients are different for every company and every day.

Now, my question is, how to output the beta & alpha for each company and for each day into a data structure?

I was reading the SAS regression documentation, but it seems that the output is rather a text than a data structure.

The code from documentation:

   proc reg;
      model y=x;
   run;

The output from the documentation:

enter image description here

There is no way that I can read over every beta for every company on every single day. There are tens of thousands of them.

Therefore, I was wondering if there is a way to output and extract the betas into a data structure?

I have background in OOP languages (python and java). Therefore the SAS can be really confusing sometimes ...

1
Also - if you are into OOP, look into PROC DS2 which is the (new, under development) OOP version of the SAS language (replacing data steps).Joe
My assumption is you'll also have a BY statement.Reeza

1 Answers

1
votes

SAS in many ways is very similar to an object oriented programming language, though of course having features of functional languages and 4GLs also.

In this case, there is an object: the output delivery system object (ODS). Every procedure in SAS 9 that produces printed output produces it via the output delivery system, and you can generally obtain that output via ODS OUTPUT if you know the name of the object.

You can use ODS TRACE to see the names of the output produced by a particular proc.

data stocks;
  set sashelp.stocks;
run;

ods trace on;
proc reg data=stocks;
  by stock;
  model close=open;
run;
ods trace off;

Note the names in the log. Then whatever you want output-wise, you just wrap the proc with ODS OUTPUT statements.

So if I want parameter estimates, I can grab them:

ods output ParameterEstimates=stockParams;
proc reg data=stocks;
  by stock;
  model close=open;
run;
ods output close;

You can have as many ODS OUTPUT statements as you want, if you want multiple datasets output.