LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 20 Jul 2004 09:22:10 -0700
Reply-To:     Bazyllll <bazyllll@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Bazyllll <bazyllll@HOTMAIL.COM>
Organization: http://groups.google.com
Subject:      Re: sas question about macro
Content-Type: text/plain; charset=ISO-8859-1

Roger Lustig <trovato@verizon.net> wrote in message news:<40F66514.8050900@verizon.net>... > 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;

Hi again, thank you for your answers. Since it was more looking like my code I tried Roger's one. But apprently I failed to put the %LET part. Should I avoid the macro start and finish? If ever I wanted to run my former code, what should I correct furthermore, cause according to the log the Norme2 isn't initialized, so I added just above its loop Norme2=0, but it didn't work. I add the entire code if ever it could help. Thanks for your friendly help.

********************* ********************* data ACPtemoin; infile 'LSMEANSACP.csv'; input Nssd$ HP5 LR5 NF5 NT5 HP8 LR8 NF8 NT8 HP12 LR12 NF12 NT12 NTII12 HP15 LR15 NF15 NT15 NTII15 HP19 LR19 NF19 NT19 NTII19 NRP MSR LoF LaF MSF MSA R_S LSSR SLA RTR12 RTR23 RTR34 RTR45 Fs12 Fs23 Fs34 Fs45 PHY DHP12 DHP45 DLR12 DLR23 DLR34 DLR45; proc print data=ACPtemoin; run;

/*Calcul des contributions etdes cosinus carrés des individus*/

%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&i; %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_47 Norme2; sum Cont_1-Cont_47 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;

/*Projection du nuage des individus dans un plan factoriel*/

%macro PROJ(tab,prin1,prin2,L1,L2);

title2 'Projection des lignées dans le plan axe1-axe2'; data PROJ; set &tab; X=&prin1; Y=&prin2; Xsys='2'; Ysys='2'; text=Nssd; keep X Y Xsys Ysys text;

proc gplot anno=PROJ; plot Y*X / vaxis=axis2 haxis=axis1 href=0 vref=0; symbol i=none; axis1 label=('&prin1') length=&L1 cm; axis2 label=(a=90 '&prin2') length=&L2 cm; run;

%mend PROJ;

/*Cercle des corrélations*/

%macro CERCLE(tab,prin1,prin2,L); title2 'Cercle des correlations dans le plan axe1-axe2'; data CERCLE; do angle=0 to 6.3 by 0.1; X=COS(angle); Y=SIN(angle); CODE=1; Xsys='2'; Ysys='2'; output; end; drop angle; data VARIABLE; set &tab; if _TYPE_='CORR'; X=Axe&prin1; Y=Axe&prin2; Code=2; Xsys='2'; Ysys='2'; text=_NAME_; keep X Y Xsys Ysys text code; data CERCLE; set CERCLE VARIABLE; proc gplot anno=CERCLE; plot Y*X=code / href=0 vref=0 vaxis=axis2 haxis=axis1 nolegend; symbol1 i=j v=none c=black; symbol2 i=none v=none c=black; axis1 label=('Axe1') length=&L cm; axis2 label=(a=90 'Axe2') length=&L cm; run; %mend CERCLE;

/*Programme principal*/

title2 'Analyse en composantes principales'; proc princomp out=ACP prefix=AXE vardef=n covariance;

var HP5 LR5 NF5 NT5 HP8 LR8 NF8 NT8 HP12 LR12 NF12 NT12 NTII12 HP15 LR15 NF15 NT15 NTII15 HP19 LR19 NF19 NT19 NTII19 NRP MSR LoF LaF MSF MSA R_S LSSR SLA RTR12 RTR23 RTR34 RTR45 Fs12 Fs23 Fs34 Fs45 PHY DHP12 DHP45 DLR12 DLR23 DLR34 DLR45;

run;

title2 'Coordonnees factorielles des lignees (tab ACP)'; proc print data=ACP; VAR Nssd AXE1-AXE41; run;

%CONTRIB(ACP,49); %PROJ(ACP,AXE1,AXE2,8,8);

title2 'Projection dans l espace 1-2-3'; data PROJ123; set ACP; X=AXE1; Y=AXE2; Z=AXE3; Xsys='2'; Ysys='2'; Zsys='2'; text=site; keep X Y Z Xsys Ysys Zsys text; goptions gsfmode=append;

proc g3D anno=PROJ123; scatter Y*X=Z / shape='POINT' rotate=85 tilt=70; label X='AXE1' Y='AXE2' Z='AXE3'; run;

title2 'Correlations variables - axes'; proc corr data=ACP outp=CORR; VAR AXE1-AXE49; with HP5 LR5 NF5 NT5 HP8 LR8 NF8 NT8 HP12 LR12 NF12 NT12 NTII12 HP15 LR15 NF15 NT15 NTII15 HP19 LR19 NF19 NT19 NTII19 NRP MSR LoF LaF MSF MSA R_S LSSR SLA RTR12 RTR23 RTR34 RTR45 Fs12 Fs23 Fs34 Fs45 PHY DHP12 DHP45 DLR12 DLR23 DLR34 DLR45; run;

%CERCLE(CORR,AXE1,AXE2,8);

/* title2 'CORRELATION ENTRE VARIABLE'; proc CORR data =altius cov outp=CORVAR nosimple; var HP5 LR5 NF5 NT5 HP8 LR8 NF8 NT8 HP12 LR12 NF12 NT12 NTII12 HP15 LR15 NF15 NT15 NTII15 HP19 LR19 NF19 NT19 NTII19 NRP MSR LoF LaF MSF MSA R_S LSSR SLA RTR12 RTR23 RTR34 RTR45 Fs12 Fs23 Fs34 Fs45 PHY; with HP5 LR5 NF5 NT5 HP8 LR8 NF8 NT8 HP12 LR12 NF12 NT12 NTII12 HP15 LR15 NF15 NT15 NTII15 HP19 LR19 NF19 NT19 NTII19 NRP MSR LoF LaF MSF MSA R_S LSSR SLA RTR12 RTR23 RTR34 RTR45 Fs12 Fs23 Fs34 Fs45 PHY; run; proc print data =CORVAR;

run; */ *GOPTIONS RESET;

**************************** *************************


Back to: Top of message | Previous page | Main SAS-L page