Date: Mon, 12 Jan 1998 11:22:27 -0800
Reply-To: Scott Carl <SCARL@THECREEK.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Scott Carl <SCARL@THECREEK.COM>
Subject: Re: Help with Macro
Content-Type: text/plain
A. Natarajan wrote:
>
> I have never understood macros in SAS, and therefore, I am not
> surprised why macros never work for me - here is my problem.
>
> I want to do 50 univariate regressions, and want to implement a macro
> solution. I thought of:
>
> data a ;
> infile 'a.dat' ;
> input y x1-x50 ;
> run ;
>
> %macro myreg (j);
> proc reg data=a ;
> model y = x{j} ;
> run ;
> %mend ;
>
> data _NULL_ ;
> array x{50} x1-x50 ;
> do j = 1 to 50 ;
> %myreg(j) ;
> end ;
>
> SAS tells me that j is unrecognized. There must be a better solution
> that the "brute force" approach of putting all 50 regressions! I'd
> appreciate a lesson in macros.
Hi,
Here is a simple non-macro alternative that I like:
data test;
do x1=1 to 100;
x2=x1+.5;
y=x1+rannor(737373)*20;
output;
end;
proc print;
* Stack the regressors;
data stack;
set test;
array xa(*) x1-x2;
do group=1 to dim(xa);
x=xa(group);
output;
end;
drop x1-x2;
proc sort; by group;
proc print;
proc reg;by group;
model y=x;
run;
quit;
Scott Carl
Marketing Statistician
Coldwater Creek
One Coldwater Creek Drive
Sandpoint, ID 83864
scarl@thecreek.com
(208) 265-7136
|