Date: Mon, 31 Jan 2000 07:26:19 -0800
Reply-To: garthnovack <garthNOgaSPAM@U.ARIZONA.EDU.INVALID>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: garthnovack <garthNOgaSPAM@U.ARIZONA.EDU.INVALID>
Organization: http://www.remarq.com: The World's Usenet/Discussions Start Here
Subject: Re: PROC IML and existing datasets from datasteps
Thanks Alfred - the proc IML is kind of a "mini world" where
the already confusing SAS syntax gets even worse! A
classmate sent me this code as an example. Notice that once
you call proc IML you must read each existing variable into
its own matrix:
(thanks, garth)
I've enclosed the copy of the program, it does a logistic
then outputs the coefficients, and then in IML it
manupulates the coefficients, so on, hope it helps
proc logistic data=final1 descending outest=PROB;
model ISSUE=DIV BM Profit FA DEPR SIZE REGUL BUSI CRDT CRDT2
MeanInt LTmean
MDiff IntStd LTstd;
output out=LOUT XBETA=Yhat;
run;
*proc print data=PROB;run;
data LP1;
set LOUT;
V2=ISSUE-Yhat;
Keep V2;
run;
*proc print data=LP1 (obs=15);run;
data PRE1;
set PROB;
x0=INTERCEP;
x1=DIV;
x2=BM;
x3=Profit;
x4=FA;
x5=DEPR;
x6=SIZE;
x7=REGUL;
x8=BUSI;
x9=CRDT;
x10=CRDT2;
x11=MeanInt;
x12=LTmean;
x13=MDiff;
x14=IntStd;
x15=LTstd;
keep x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15;
run;
*proc print data=PRE1;run;
proc reg data=final1 noprint outest=OLS;
model MMAT=DIV BM Profit FA DEPR SIZE REGUL BUSI CRDT CRDT2
MeanInt LTmean
MDiff IntStd LTstd;
output out=ROUT R=V1;
run;
*proc print data=OLS;run;
data RP1;
set ROUT;
Keep V1;
run;
data RL;
merge RP1 LP1;
run;
*proc print data=RP1 (obs=15);run;
data PRE2;
set OLS;
y0=INTERCEP;
y1=DIV;
y2=BM;
y3=Profit;
y4=FA;
y5=DEPR;
y6=SIZE;
y7=REGUL;
y8=BUSI;
y9=CRDT;
y10=CRDT2;
y11=MeanInt;
y12=LTmean;
y13=MDiff;
y14=IntStd;
y15=LTstd;
keep y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 y11 y12 y13 y14 y15;
run;
*proc print data=PRE2;run;
proc iml;
start main;
use PRE1;
read all var{x0} into P0;
read all var{x1} into P1;
read all var{x2} into P2;
read all var{x3} into P3;
read all var{x4} into P4;
read all var{x5} into P5;
read all var{x6} into P6;
read all var{x7} into P7;
read all var{x8} into P8;
read all var{x9} into P9;
read all var{x10} into P10;
read all var{x11} into P11;
read all var{x12} into P12;
read all var{x13} into P13;
read all var{x14} into P14;
read all var{x15} into P15;
Pi2=P0//P1//P2//P3//P4//P5//P6//P7//P8//P9//P10//P11//P12//P
13//P14//P15;
use PRE2;
read all var{y0} into Pe0;
read all var{y1} into Pe1;
read all var{y2} into Pe2;
read all var{y3} into Pe3;
read all var{y4} into Pe4;
read all var{y5} into Pe5;
read all var{y6} into Pe6;
read all var{y7} into Pe7;
read all var{y8} into Pe8;
read all var{y9} into Pe9;
read all var{y10} into Pe10;
read all var{y11} into Pe11;
read all var{y12} into Pe12;
read all var{y13} into Pe13;
read all var{y14} into Pe14;
read all var{y15} into Pe15;
Pi1=Pe0//Pe1//Pe2//Pe3//Pe4//Pe5//Pe6//Pe7//Pe8//Pe9//Pe10//
Pe11//Pe12//Pe13
//Pe14//Pe15;
J1=j(16,13,0);
J1[1,1]=1;
J1[3,2]=1;
do i=0 to 10;
J1[6+i,3+i]=1;
end;
J2=j(16,12,0);
do i=1 to 7;
J2[i,i]=1;
end;
do i=0 to 4;
J2[12+i,8+i]=1;
end;
H=Pi2||J1;
G=Pi1||J2;
alfa1=inv(H`*H)*H`*Pi1;
Pi1h=H*alfa1;
resid1=Pi1-Pi1h;
sse1=resid1`*resid1;
df1=nrow(H)-ncol(H);
mse1=sse1/df1;
covb1=inv(H`*H)#mse1;
stdb1=sqrt(vecdiag(covb1));
t_stat1=alfa1/stdb1;
sst1=Pi1`*Pi1;
R21=sse1/sst1;
alfa2=inv(G`*G)*G`*Pi2;
Pi2h=G*alfa2;
resid2=Pi2-Pi2h;
sse2=resid2`*resid2;
df2=nrow(G)-ncol(G);
mse2=sse2/df2;
covb2=inv(G`*G)#mse2;
stdb2=sqrt(vecdiag(covb2));
t_stat2=alfa2/stdb2;
sst2=Pi2`*Pi2;
R22=sse2/sst2;
print , alfa1 t_stat1 R11, alfa2 t_stat2 R22;
finish;
run;
* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping. Smart is Beautiful
|