|
Dear Bazyllll:
The Macro Fairy is punishing you for using a macro when you don't need
one! Specifically, he/she/it caused you to write one of your %END;
statements as END;.
All you need is two %LET statements in open code, and a few arrays.
%let tab=mydata;
%let p=12; ***or whatever;
proc means data=&tab noprint vardef=n;
var AXE1-AXE&p;
output out=LAMBDA var=LAMBDA1-LAMBDA&p n=N;
run;
***** You don't need this next part either;
/*
data LAMBDA;
set LAMBDA;
Code=1;
data CONTRIB;
set &tab;
Code=1;
*/
data CONTRIB2;
array lambda (&p);
if _n_=1 then do;
set lambda;
*** Do this division only once!!!;
do I=1 to &p;
lambda(I)=lambda(I)/N;
end;
end;
set contrib;
* merge CONTRIB LAMBDA;
* by Code;
* data CONTRIB;
* set CONTRIB;
array carre(&p);
array axe(&p);
array cos2_(&p);
norme2=0;
do I=1 to &p;
carre(I)=axe(I)*axe(I);
norme2=norme2 + carre(I);
**** No more dividing by N every time!;
cont_(I)=carre(I)/lambda(I);
end;
do I=1 to &p;
cos2_(I)=carre(I)/norme2;
end;
cos2_12a=cos2_1 + cos2_2;
cos2_123a=cos2_12 + cos2_3;
keep Nssd Norme2 Cont_1-Cont_&p Cos2_1-Cos2_&p ;
run;
title2 'Contributions relatives des sites a l inertie des axes';
proc print data=CONTRIB2;
var Nssd Cont_1-Cont_41 Norme2;
sum CONT_1-CONT_41 Norme2;
run;
title2 'Qualite de la representation des sites (cosinus carres)';
proc print data=CONTRIB2;
var Nssd COS2_1 COS2_2 COS2_12a COS2_3 COS2_123a;
run;
Enjoy!
Roger
Bazyllll wrote:
> Hi I'm a student in biology and need an ACP procedure for my work. I'm
> calling a macro that seems not to compile with a DO because it seems
> not to end.
> What's wrong with it, can you help me please?
> I think it's a simple syntax problem but i'm not familiar with macro.
> Hope you'll can help me. Thanks in advance.
> Bazyllll
>
> %macro CONTRIB(tab,p);
>
> proc means data=&tab noprint vardef=n;
> var AXE1-AXE&p;
> output out=LAMBDA var=LAMBDA1-LAMBDA&p n=N;
> data LAMBDA;
> set LAMBDA;
> Code=1;
> data CONTRIB;
> set &tab;
> Code=1;
> data CONTRIB;
> merge CONTRIB LAMBDA;
> by Code;
> data CONTRIB;
> set CONTRIB;
> %do i=1 %to &p; Carre&i=Axe&i*Axe&i; end;
> Norme2 = %do i=1 %to &p; +Carre&i %end;
> %do i=1 %to &p; Cont_&i=Carre&i/Lambda&i/N; %end;
> %do i=1 %to &p; Cos2_&i=Carre&i/Norme2; %end;
> keep Nssd Norme2 Cont_1-Cont_&p Cos2_1-Cos2_&p;
> run;
>
> title2 'Contributions relatives des sites a l inertie des axes';
> proc print data=CONTRIB;
> var Nssd Cont_1-Cont_41 Norme2;
> sum CONT_1-CONT_41 Norme2;
> run;
>
> title2 'Qualite de la representation des sites (cosinus carres)';
> data CONTRIB;
> set CONTRIB;
> COS2_12=COS2_1+COS2_2;
> COS2_123=COS2_12+COS2_3;
> proc print data=CONTRIB;
> var Nssd COS2_1 COS2_2 COS2_12 COS2_3 COS2_123;
> run;
>
> %mend CONTRIB;
|