dear all,
i have the data of 163 companies stocks returns which are regressed on market return for every year separately from 2010 to 2021. i am using the below mentioned SAS code for running the regression. I need help on saving the regression residuals in a separate file
the my input data format is as follows
Date | year | rm | C1 | C2 | C3 | ………. | C163 |
5/4/2010 | 2010 | 1.446447751 | 0.034732 | -1.30527 | 1.414732 | 0.114732 | |
6/4/2010 | 2010 | -0.059983621 | 0.204732 | 0.124732 | -0.32527 | -1.17527 | |
7/4/2010 | 2010 | 0.145802794 | 2.394732 | 0.174732 | 1.314732 | -0.02527 | |
8/4/2010 | 2010 | -1.330004037 | -1.26527 | -2.06527 | -0.22527 | -0.13527 | |
9/4/2010 | 2010 | 1.059164775 | -0.48527 | 0.384732 | -0.28527 | 0.164732 | |
12/4/2010 | 2010 | -0.428505517 | -0.74641 | -1.14641 | -0.91641 | 0.613589 | |
13/4/2010 | 2010 | -0.330592313 | -0.90641 | 3.443589 | 0.973589 | 1.223589 | |
15/4/2010 | 2010 | -0.947853211 | -0.47641 | 0.373589 | -0.59641 | -1.14641 | |
16/4/2010 | 2010 | -0.225215255 | -0.53641 | -1.36641 | -0.73641 | 0.093589 | |
19/4/2010 | 2010 | -1.142655323 | -1.46617 | -2.06617 | 1.773835 | -0.57617 | |
20/4/2010 | 2010 | 0.490844146 | 0.133835 | 0.743835 | 6.183835 | 1.563835 | |
21/4/2010 | 2010 | 0.266412308 | 1.143835 | 0.083835 | 3.933835 | 2.383835 | |
22/4/2010 | 2010 | 0.448918494 | -1.31617 | 0.323835 | 1.743835 | 1.013835 | |
23/4/2010 | 2010 | 0.641143665 | -1.81617 | 0.593835 | 1.713835 | 0.183835 | |
26/4/2010 | 2010 | 0.32919628 | 0.533835 | 0.693835 | 1.893835 | -2.44617 | |
27/4/2010 | 2010 | -0.281432562 | -0.52617 | 0.883835 | 1.043835 | -0.87617 | |
28/4/2010 | 2010 | -1.781733268 | 0.543835 | -1.99617 | -2.63617 | -1.67617 | |
29/4/2010 | 2010 | 0.723121179 | -1.19617 | -0.86617 | -0.35617 | -0.38617 | |
30/4/2010 | 2010 | 0.436734309 | 0.973835 | -1.02617 | 0.103835 | -0.24617 | |
3/5/2010 | 2010 | -1.068325706 | -0.35601 | 1.94399 | 0.35399 | -1.40601 | |
4/5/2010 | 2010 | -1.447877506 | -2.72601 | 0.48399 | -0.33601 | -2.42601 | |
5/5/2010 | 2010 | -0.475449956 | 0.73399 | -0.80601 | 0.25399 | -2.13601 | |
6/5/2010 | 2010 | -0.682630399 | -1.12601 | 0.29399 | 0.02399 | -1.91601 | |
7/5/2010 | 2010 | -1.456350078 | -1.33601 | -0.30601 | -0.65601 | -4.86601 | |
10/5/2010 | 2010 | 3.422403185 | 2.813835 | 0.823835 | 3.373835 | 6.043835 | |
11/5/2010 | 2010 | -1.128498123 | -0.40617 | -0.05617 | 0.223835 | 1.703835 | |
12/5/2010 | 2010 | 0.382171782 | -0.83617 | 0.253835 | -0.16617 | 2.803835 | |
13/5/2010 | 2010 | 0.41438802 | 1.443835 | 2.953835 | 0.343835 | 2.533835 | |
14/5/2010 | 2010 | -1.678911592 | 0.213835 | -2.05617 | 2.253835 | -3.73617 | |
17/5/2010 | 2010 | -0.678170681 | -3.32632 | -1.35632 | -2.28632 | -1.86632 |
In the above file, rm is market return and C1 to C163 are the returns of 163 stocks.
i need the output in the following format
Date | year | C1_residual | C2_residual | C3_residual | ………. | C163_residual |
i am using the following code for running the regression
proc reg data=have;
model C1 - C163= rm ;
BY year;
run;
quit;
please help me writing the code to get output in the above mentioned format
thanks in advance
Use the OUTPUT command in PROC REG. An example is given here:
https://documentation.sas.com/doc/en/pgmmvacdc/9.4/statug/statug_reg_syntax10.htm
Use the OUTPUT command in PROC REG. An example is given here:
https://documentation.sas.com/doc/en/pgmmvacdc/9.4/statug/statug_reg_syntax10.htm
You are allowed to use any valid SAS variable list.
r=resid_c1-resid_c163
Hello @srikanthyadav44
Considering the four c values in your data, the code shoutd be something like as shown below.
Please note the output file will be in the work library.
Modify as needed.
proc reg data=your_source_data;
model c1 c2 c3 c4 =rm ;
by year;
output out=residual_output
p=c1hat c2hat c3hat c4hat
r=c1resid c2resid c3resid c4resid ;
run;
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.