dear all,
i have to run the regression where in the independent varaibles will be same, but dependent variables will change each time.
I have nearly 200 dependent variables.
i have to run the regression repeatedly for 200 times for each dependent variable.
Finally, I have to save the R-squared and adjusted R-squared value of each regression in a separate file along with the name of the dependent variable.
the format of my file is as follows
IV_1 | IV_2 | DV_1 | DV_2 | ……………. | DV_200 |
-1.67137 | -1.28567 | -1.41424 | -1.7678 | ……………. | -1.83851 |
-0.20913 | -0.16087 | -0.17696 | -0.2212 | ……………. | -0.23005 |
-0.41298 | -0.31768 | -0.34944 | -0.4368 | ……………. | -0.45428 |
-0.61455 | -0.47273 | -0.52001 | -0.65001 | ……………. | -0.67601 |
0.260277 | 0.200213 | 0.220235 | 0.275293 | ……………. | 0.286305 |
-0.13165 | -0.10127 | -0.1114 | -0.13925 | ……………. | -0.14482 |
0.065317 | 0.050244 | 0.055268 | 0.069085 | ……………. | 0.071849 |
2.116535 | 1.628104 | 1.790914 | 2.238643 | ……………. | 2.328188 |
-0.64197 | -0.49382 | -0.54321 | -0.67901 | ……………. | -0.70617 |
1.636049 | 1.258499 | 1.384349 | 1.730436 | ……………. | 1.799654 |
-0.04114 | -0.03165 | -0.03481 | -0.04351 | ……………. | -0.04525 |
-1.18318 | -0.91014 | -1.00116 | -1.25144 | ……………. | -1.3015 |
0.87525 | 0.673269 | 0.740596 | 0.925745 | ……………. | 0.962775 |
0.202968 | 0.156129 | 0.171742 | 0.214678 | ……………. | 0.223265 |
0.516805 | 0.397543 | 0.437297 | 0.546621 | ……………. | 0.568486 |
0.137332 | 0.10564 | 0.116204 | 0.145255 | ……………. | 0.151065 |
-1.62652 | -1.25117 | -1.37628 | -1.72035 | ……………. | -1.78917 |
-2.7442 | -2.11093 | -2.32202 | -2.90252 | ……………. | -3.01862 |
-0.20355 | -0.15658 | -0.17224 | -0.2153 | ……………. | -0.22391 |
-0.12738 | -0.09799 | -0.10779 | -0.13473 | ……………. | -0.14012 |
-0.99255 | -0.7635 | -0.83985 | -1.04981 | ……………. | -1.0918 |
0.33774 | 0.2598 | 0.28578 | 0.357225 | ……………. | 0.371514 |
IV is independent variable and DV is dependent variable
please helpe me writing a SAS code for this
thanks in advance
proc reg data=have;
model dv_1-dv_200 = iv_1 iv_2;
run;
quit;
Transpose, sort and use by in proc reg. Then it all happens in one step.
Just a quick example:
data have;
infile datalines dlm='09'x dsd;
input IV_1 IV_2 DV_1 DV_2;
datalines;
-1.67137 -1.28567 -1.41424 -1.7678
-0.20913 -0.16087 -0.17696 -0.2212
-0.41298 -0.31768 -0.34944 -0.4368
-0.61455 -0.47273 -0.52001 -0.65001
0.260277 0.200213 0.220235 0.275293
-0.13165 -0.10127 -0.1114 -0.13925
0.065317 0.050244 0.055268 0.069085
2.116535 1.628104 1.790914 2.238643
-0.64197 -0.49382 -0.54321 -0.67901
1.636049 1.258499 1.384349 1.730436
-0.04114 -0.03165 -0.03481 -0.04351
-1.18318 -0.91014 -1.00116 -1.25144
0.87525 0.673269 0.740596 0.925745
0.202968 0.156129 0.171742 0.214678
0.516805 0.397543 0.437297 0.546621
0.137332 0.10564 0.116204 0.145255
-1.62652 -1.25117 -1.37628 -1.72035
-2.7442 -2.11093 -2.32202 -2.90252
-0.20355 -0.15658 -0.17224 -0.2153
-0.12738 -0.09799 -0.10779 -0.13473
-0.99255 -0.7635 -0.83985 -1.04981
0.33774 0.2598 0.28578 0.357225
;
proc transpose data=have out=trans;
by iv_1 iv_2 notsorted;
var dv:;
run;
proc sort data=trans;
by _name_;
run;
dear KurtBremser
how to modify the SAS code suggested by you, if i want to run the code with an excel file imported into SAS.
thanks in advance
Just apply the transpose and sort, using the actual variable names.
dear KurtBremser
thanks for your prompt reply.
I understood tranpose and sort, but what changes i have to do to the following code to run the regression with imported excel file.
I may be right that the below code is for the data directly entered in SAS, because you are using datalines.
data have;
infile datalines dlm='09'x dsd;
input IV_1 IV_2 DV_1 DV_2;
datalines;
and also can you please explain me what is 'dlm='09' x dsd
Hello, @srikanthyadav44
A much simpler approach appears in message 4 of this thread. No transposing needed.
This step is just there to create an example dataset, in a way that allows everybody who reads the post to recreate it with a simple copy/paste and submit. It is not needed for your application, as you already have your data.
@srikanthyadav44 wrote:
dear all,
i have to run the regression where in the independent varaibles will be same, but dependent variables will change each time.
I have nearly 200 dependent variables.
i have to run the regression repeatedly for 200 times for each dependent variable.
Finally, I have to save the R-squared and adjusted R-squared value of each regression in a separate file along with the name of the dependent variable.
PROC REG allows multiple dependent variables. Thus you need one PROC REG step. No need to transpose your data.
Use
ods output modelfit=modelfit;
to capture the R-squared values.
dear PaigeMiller
i am unable to solve the problem of running the regression repeatedly and saving the R-squared values in a separate sheet.
kindly suggest me a SAS code more clearly and completely.
thanks in advance
proc reg data=have;
model dv_1-dv_200 = iv_1 iv_2;
run;
quit;
thank you Mr. PaigeMiller. for your prompt reply
the SAS code suggested by you is working excellently.
after getting the regression results i run the code suggested by you earlier to get the R-squared values in a separate file
"ods output modelfit=modelfit;"
But it is not working. my SAS university edition software is hanging when i run that code.
if there is any other alternative way to get the R-squared values, please suggest me.
thanks in advance
But it is not working.
This is not enough information. You need to show us the LOG of PROC REG, including the code and error message. Please click on the {i} icon and paste the log into the window that appears. Do not skip this step.
dear Mr. PaigeMiller
when i run the " ods output modelfit=modelfit;" i am gettting the following message in log
dear Mr. Paigemiller
i run the SAS code as following and then i got the error as mentioned in the previous reply
proc reg data=stocks;
model Y1 - Y5=X1 X2;
run;
quit;
ods output modelfit=modelfit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.