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 (May 2010, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 3 May 2010 10:15:32 -0400
Reply-To:     "P. Cristian Gugiu" <crisgugiu@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "P. Cristian Gugiu" <crisgugiu@YAHOO.COM>
Subject:      Help with macro variables

Hi all. I wrote code for calculating a double integral using the Trapezoid Rule. However, I need to pass a value out of the macro and keep running into problems. Can someone tell me how I can assign the value for the variable "Volume" to a macro variable that I can use outside of the macro.

Thanks, Cristian

%Let Pi=3.1415926535897932384626433832795; %Macro Trapezoid(minX=,maxX=,minY=,maxY=,func=,lbl=); %Global mu; data _NULL_; delta=.1; dx=delta; dy=delta; sum=0; do x=&minX to &maxX by dx; if round(x,dx) eq &minX OR round(x,dx) eq &maxX then mX=1; else mX=2; do y=&minY to &maxY by dy; if round(y,dy) eq &minY OR round(y,dy) eq &maxY then mY=1; else mY=2; sum=sum + mX*mY*(&func); end; end; Volume=round(0.25*dx*dy*sum,.00000001); %let mu= input(Volume,best4.); put "&lbl=" Volume; %put &mu; run;quit; %Mend Trapezoid; %let mu1=29.9924961; /* Mean of X */ %let var1=23.2736469; /* Variance of X */ %let mu2=9.99274913; /* Mean of Y */ %let var2=0.24619424; /* Variance of Y */ %let rho=0.75046; /* Correlation b/w X and Y */

%let g_xy=(sqrt(abs(x*y))); /* Function */ %let pdf = (1/(2*&Pi*sqrt(&var1*&var2*(1-&rho**2))))*exp(-(1/(2*(1- &rho**2)))*(((x-&mu1)**2)/&var1 + ((y-&mu2)**2)/&var2 - 2*&rho*(x-&mu1)*(y- &mu2)/sqrt(&var1*&var2)));

/* Estimate mean of E(Z)=E[g(X,Y)] */ %let function=&g_xy * &pdf; %Trapezoid(minX=-100,maxX=100,minY=-100,maxY=100,func=&function,lbl=Mean);

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