%macro conelip(version, data=_LAST_, x1= , x2= , mean= , conf= ); %if &version ne %then %put CONELIP macro Version 1.0; symbol1;symbol2; symbol1 v=star c=red ; symbol2 v=none c=black i=j; %let confi=%sysevalf(&conf*100); data &data; set &data; x1=&x1; x2=&x2; id=1; /*Proc CORR will give the mean vector and the covariance matrix S*/ /*With S we will use the Cholesky Decomposition to compute points*/ /*within the confidence ellipse. */ proc corr data=&data cov outp=corrs noprint; var x1 x2; run; data obs(keep=n);set corrs; if upcase(_type_)='N' then do; n=x1; output; end; data mean(keep=meanx1 meanx2);set corrs; if upcase(_type_)='MEAN' then do; meanx1=x1; meanx2=x2; output; end; data choles1;set corrs; if upcase(_type_)='COV' and upcase(_name_)='X1' then do ; A11=x1; A12=x2; output; end; data choles2;set corrs; if upcase(_type_)='COV' and upcase(_name_)='X2' then do; A22=x2; output; end; data choles(keep= a b c meanx1 meanx2 n);merge choles1 choles2 mean obs; a=sqrt(A11); b=A12/a; c=sqrt(A22-(b**2)); %if %upcase(&mean)=NO %then %do; data b05;set choles;/*Computes the Confidence Ellipse*/ do t= 0 to 6.2831853 by .01; /*Goes from 0 to 2*pi*/ s=sin(t); cos=cos(t); d=sqrt(cinv(&conf,2)); x1= meanx1+(a*d*cos); x2= meanx2+ b*d*cos+(c*d*s); drop t s cos d; id=2; output; end; data b; /*Puts the datasets together*/ set &data b05; run; title "&confi.% Confidence Ellipse About the Data"; proc gplot data=b; plot x2*x1=id; run; %end; %if %upcase(&mean)=YES %then %do; data b05;set choles;/*Computes the 95% Confidence Ellipse*/ do t= 0 to 6.2831853 by .01; /*Goes from 0 to 2*pi*/ s=sin(t); cos=cos(t); d=sqrt(((n-1)*2*finv(&conf,2,n-2))/(n*(n-2))); x1= meanx1+(a*d*cos); x2= meanx2+ b*d*cos+(c*d*s); drop t s cos ; id=2; output; end; data b; /*Puts the datasets together*/ set &data b05; run; title "&confi.% Confidence Ellipse About the Mean Vector"; proc gplot data=b; plot x2*x1=id; run; %end; title; %mend;