Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing custom probbnrm function

Status
Not open for further replies.

SergeSU

Programmer
Dec 7, 2006
1
US
Hello!

I am trying to write a SAS (macro) function that returns a value, in an effort to create a PROBBNRM function analog that allows customized lower/upper bounds and accepts non-standardized bivariate normal distribution means/variances.

I have written a macro function (I think) that computes the desired probability from user input,

%JointProbability(mu1, mu2, sigma1, sigma2, corr, critx1, critx2, crity1, crity2);quit;

The code for the macro is below, but all it does is assign the resulting probability to a global variable MyOutput, rather than return a value. I intend to use this function in proc nlp to fit a bivariate model (Platform: Windows 2K, SAS 9 used).

Would anyone have any suggestions on how to proceed?

Thank you!!
Serge


%macro JointProbability(xMean,yMean,xSD,ySD,rho,xLower,xUpper,yLower,yUpper);
data;
m1=&xMean;m2=&yMean;
s1=&xSD;s2=&ySD;
r=ρ
cx1=&xLower;cx2=&xUpper;
cy1=&yLower;cy2=&yUpper;
zx1=(cx1-m1)/s1;zx2=(cx2-m1)/s1;zx3=(cx1-m1)/s1;zx4=(cx2-m1)/s1;
zy1=(cy1-m2)/s2;zy2=(cy2-m2)/s2;zy3=(cy2-m2)/s2;zy4=(cy1-m2)/s2;
p_out=probbnrm(zx2,zy2,r)-probbnrm(zx3,zy3,r)-probbnrm(zx4,zy4,r)+probbnrm(zx1,zy1,r);
%global MyOutput;
call symput('MyOutput',p_out);
run;
%mend;
 
First off, that macro will end your datastep if you run it within a datastep as it has a data statement and run statement in it. You should remove those.

You should be able to use this as an example of what you can do...
Code:
%macro test();
  %let mvar = tester;
  &mvar;
%mend test;

data _null_;
  new_var = "%test";

  put new_var=;
run;

new_var=tester
As you can see, putting the macro variable on line there returns the value. You can do the same ting without the quotes for a numeric value.
Code:
%macro test();
  %let mvar = 5;
  &mvar;
%mend test;

data _null_;
  new_var = %test;

  put new_var=;
run;

new_var=5;
Enjoy.

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top