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:         Thu, 15 Jul 2004 06:52:28 -0400
Reply-To:     "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Subject:      Re: sas question about macro

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;

In the sum of squares computation, the 'end' after Axe&i; should be '%end' Also, at then end of the NORME2 line you need another semicolon (;). This is a 'statement closing ;' The ; that is already there only closes the %do %end loop that is internal to the NORME2 statement being generated.

However, I would say you don't even need macro here. Who ever wrote it just wanted to get the numbers out and didn't take the time to reduce the number of data steps. Only one data step is needed!

Also, NSSD is never computed, so one must presume data set passed in as 'tab' has a column named NSSD.

I'm no statistician so I don't recognize what you are computing. My guess is there is a SAS Proc or Function that already does so.

Anyway, here is the same process as a single data step. The sensible 'macroization' would be to parameterize data= and p= again.

----- data foo; do rowid = 1 to 1000; array axe axe1-axe20; retain seed 2669; do i = 1 to dim(axe); axe[i] = 10 * (i + ranuni(seed)); end; output; end; drop i seed; run;

proc means data=foo noprint vardef=n; var axe1-axe20; output out=lambda var=lambda1-lambda20 n=n; run;

data contrib; set foo; if _n_ = 1 then set lambda;

array carre carre1-carre20; array axe axe1 -axe20; do i = 1 to 20; carre[i] = axe[i]**2; end; norme2 = sum (of carre1-carre20);

array cont_ cont_1 -cont_20; array cos2_ cos2_1 -cos2_20; array lambda lambda1-lambda20; do i = 1 to 20; cont_[i] = carre[i] / lambda[i] / N; cos2_[i] = carre[i] / norme2; end;

cos2_12 = sum(cos2_1 , cos2_2); cos2_123 = sum(cos2_12 , cos2_3); run; -----

-- Richard A. DeVenezia http://www.devenezia.com/downloads/sas/samples/


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