Date: Sat, 20 Mar 2004 22:37:32 -0500
Reply-To: Quentin McMullen <quentin_mcmullen@BROWN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Quentin McMullen <quentin_mcmullen@BROWN.EDU>
Subject: Re: Help with Running Several Regressions in a Loop
Hi Tamer,
When you are thinking about putting a proc inside a loop, typically you
wold be thinking about the macro language.
In this case, however, I think you may be able to do this without macro.
I suggest you expand your data so that each record is output once for each
year-group it belongs to. So a record from 1998 would be output 3 times:
once for year_group=1996-1998, once for 1997-1999, and once for 1998-
2000. With the data in that format, you can run all the models you want
(I think) with one proc step:
proc reg;
model y1 y2 y3=x;
by final_year;
run;
Below is a quick'n'dirty example of how I'm thinking it could work.
data a;
input year x y1 y2 y3;
cards;
1987 1 2 3 4
1988 5 6 7 8
1989 9 10 11 12
1990 13 14 15 16
1991 17 18 19 20
;
run;
data b;
set a;
*expand data;
do final_year=1989 to 1991;
if (final_year-3)<year<=final_year then output;
end;
run;
proc print data=b;
run;
proc sort data=b;
by final_year;
run;
proc reg data=b;
model y1 y2 y3=x;
by final_year;
run;
HTH,
--Quentin
On Sat, 20 Mar 2004 14:40:51 -0800, Tamer Abdelgawad
<tabdelgawad@YAHOO.COM> wrote:
>Hello:
>
>I have a data set with (financial) daily data from 1987 to 2003 (about
>4300 observations). The set has the dependent variables Y1 ... Yn,
>(n=20), and a single independent variable X. For each of the 20
>dependent variables, I'd like to run several regressions on X over
>different time intervals. So for Y1, I'd like to regress Y1 on X for
>the years 1987-1989, 1988-1990, 1989-1991, ..., 2000-2003.
>
>Needless to say, I don't want to run each of these regressions one at
>a time. I'd like to be able to enter the name of the dependent
>variable at the top of the program, and have a loop run the
>regressions for each of the time periods. In *pseudo-code*, what I
>have in mind is:
>
>
>%let indep = Y1;
>
>do final_year = 1989 to 2003;
> extract subset of data from (final_year - 2) to final year;
> run regression of &indep on X;
>end;
>
>export the results to a single excel spreadsheet for &indep;
>
>
>I know that I'd use PROC REG, and I can figure out the syntax for
>myself, but I'm confused by flow control in SAS. It seems like I'd
>want to put DATA and PROC steps *inside* the DO loop, but I don't
>think that's legal. Any help ( pseudo-code would be fine) would be
>greatly appreciated.
>
>Please respond to the newsgroup.
>
>TIA,
>Tamer
|