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 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_1IV_2DV_1DV_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.2602770.2002130.2202350.275293…………….0.286305
-0.13165-0.10127-0.1114-0.13925…………….-0.14482
0.0653170.0502440.0552680.069085…………….0.071849
2.1165351.6281041.7909142.238643…………….2.328188
-0.64197-0.49382-0.54321-0.67901…………….-0.70617
1.6360491.2584991.3843491.730436…………….1.799654
-0.04114-0.03165-0.03481-0.04351…………….-0.04525
-1.18318-0.91014-1.00116-1.25144…………….-1.3015
0.875250.6732690.7405960.925745…………….0.962775
0.2029680.1561290.1717420.214678…………….0.223265
0.5168050.3975430.4372970.546621…………….0.568486
0.1373320.105640.1162040.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.337740.25980.285780.357225…………….0.371514

IV  is independent variable and DV is dependent variable 

 

please helpe me writing a SAS code for this

 

thanks in advance  

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc reg data=have;
    model dv_1-dv_200 = iv_1 iv_2;
run;
quit;
--
Paige Miller

View solution in original post

19 REPLIES 19
Kurt_Bremser
Super User

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;
srikanthyadav44
Quartz | Level 8

dear 

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 

srikanthyadav44
Quartz | Level 8

dear  

 

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

PaigeMiller
Diamond | Level 26

Hello, @srikanthyadav44 

A much simpler approach appears in message 4 of this thread. No transposing needed.

--
Paige Miller
Kurt_Bremser
Super User

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.

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
srikanthyadav44
Quartz | Level 8

dear 

 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 

PaigeMiller
Diamond | Level 26
proc reg data=have;
    model dv_1-dv_200 = iv_1 iv_2;
run;
quit;
--
Paige Miller
srikanthyadav44
Quartz | Level 8

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

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
srikanthyadav44
Quartz | Level 8

dear Mr.

 

when i run the " ods output modelfit=modelfit;" i am gettting the following message in log

 

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
NOTE: ODS statements in the SAS Studio environment may disable some output features.
73
74 ods output modelfit=modelfit;
75
76 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 
please help in resolving this problem
 
thanks in advance 
 

 

srikanthyadav44
Quartz | Level 8

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;

 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 19 replies
  • 1769 views
  • 4 likes
  • 4 in conversation