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

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

DateyearrmC1C2C3……….C163
5/4/201020101.4464477510.034732-1.305271.414732 0.114732
6/4/20102010-0.0599836210.2047320.124732-0.32527 -1.17527
7/4/201020100.1458027942.3947320.1747321.314732 -0.02527
8/4/20102010-1.330004037-1.26527-2.06527-0.22527 -0.13527
9/4/201020101.059164775-0.485270.384732-0.28527 0.164732
12/4/20102010-0.428505517-0.74641-1.14641-0.91641 0.613589
13/4/20102010-0.330592313-0.906413.4435890.973589 1.223589
15/4/20102010-0.947853211-0.476410.373589-0.59641 -1.14641
16/4/20102010-0.225215255-0.53641-1.36641-0.73641 0.093589
19/4/20102010-1.142655323-1.46617-2.066171.773835 -0.57617
20/4/201020100.4908441460.1338350.7438356.183835 1.563835
21/4/201020100.2664123081.1438350.0838353.933835 2.383835
22/4/201020100.448918494-1.316170.3238351.743835 1.013835
23/4/201020100.641143665-1.816170.5938351.713835 0.183835
26/4/201020100.329196280.5338350.6938351.893835 -2.44617
27/4/20102010-0.281432562-0.526170.8838351.043835 -0.87617
28/4/20102010-1.7817332680.543835-1.99617-2.63617 -1.67617
29/4/201020100.723121179-1.19617-0.86617-0.35617 -0.38617
30/4/201020100.4367343090.973835-1.026170.103835 -0.24617
3/5/20102010-1.068325706-0.356011.943990.35399 -1.40601
4/5/20102010-1.447877506-2.726010.48399-0.33601 -2.42601
5/5/20102010-0.4754499560.73399-0.806010.25399 -2.13601
6/5/20102010-0.682630399-1.126010.293990.02399 -1.91601
7/5/20102010-1.456350078-1.33601-0.30601-0.65601 -4.86601
10/5/201020103.4224031852.8138350.8238353.373835 6.043835
11/5/20102010-1.128498123-0.40617-0.056170.223835 1.703835
12/5/201020100.382171782-0.836170.253835-0.16617 2.803835
13/5/201020100.414388021.4438352.9538350.343835 2.533835
14/5/20102010-1.6789115920.213835-2.056172.253835 -3.73617
17/5/20102010-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 

DateyearC1_residualC2_residualC3_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 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
PaigeMiller
Diamond | Level 26

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

 

 

--
Paige Miller
srikanthyadav44
Quartz | Level 8
dear
in your referred source, the following code is given
proc reg data=a;
model y z=x1 x2;
output out=b
p=yhat zhat
r=yresid zresid;
run;
in that example, only two dependent variables(y and z) were there so, it was mentioned directly.
but, for my dataset, i have 163 dependent variables. i cannot mention the residual names for all the 163 variables.
is there any alternative ????
thanks in advance
PaigeMiller
Diamond | Level 26

You are allowed to use any valid SAS variable list.

 

r=resid_c1-resid_c163

 

--
Paige Miller
Sajid01
Meteorite | Level 14

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;

  

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
  • 4 replies
  • 2366 views
  • 3 likes
  • 3 in conversation