2
votes

Here's my macro, below. The variables var1, var2, var3, VR, and maxwt are not input to the macro, and are not on a file. They are intermediate results which are calculated inside the macro. When I execute in in SAS 9.3, I get a message like this:

1      var1 = &dcount1 * (&spop1/&refpr1)**2;
       ----
       180

ERROR 180-322: Statement is not valid or it is used out of proper order.

Macro:

%macro confi (aart,dcount1,dcount2,dcount3,spop1,spop2,spop3,refpr1=0.53468238,refpr2=0.30153350,refpr3=0.16378412);
    var1 = &dcount1 * (&spop1/&refpr1)**2;
    var2 = &dcount1 * (&spop2/&refpr2)**2;
    var3 = &dcount3 * (&spop1/&refpr3)**2;

    VR = var1+var2+var3;

    maxwt = max(&refpr1 &refpr2 &refpr3);

    CI_low = (VR/ 2*&aart)) * cinv(0.025,2*(&aart**2)/VR);
    CI_high = (( VR + maxwt**2) / (2*(&aart+maxwt)))* cinv(0.975, 2*(&aart+maxwt)**2/(VR + maxwt**2));

    %put &aart CI_low CI_high;

%mend confi;

%confi (aart=1000, dcount1=20, dcount2=70, dcount3= 10. spop1=3000, spop2=3000, spop3=200);
2

2 Answers

1
votes

That macro would have to be executed inside of a data step. Those are data step variables and statements and can't be executed in open code.

You also can't use %put for that purpose - you need to use put.

1
votes
  1. You are missing the datastep to calculate all your non-macro variables.
  2. When you call a MACRO to execute, it is a BEST PRACTICE not to put ; at the end of the line.
  3. On the CI_LOW arithmetic operation you have mismatch parenthesis.
  4. When you call the macro %confi, you are assigning dcount3 variable value wrong, you need a comma, not a dot.
  5. When you declare a Macro, you don't assign values there, only declare variables.
  6. On the Max Function, the variables need to be separated by commas.

Try this:

Options Macrogen Symbolgen;
%macro confi (aart,dcount1,dcount2,dcount3,spop1,spop2,spop3,refpr1,refpr2,refpr3); 

data _null_;
var1 = &dcount1 * (&spop1/&refpr1)**2; 
var2 = &dcount1 * (&spop2/&refpr2)**2; 
var3 = &dcount3 * (&spop1/&refpr3)**2;
VR = var1+var2+var3;

maxwt = max(&refpr1, &refpr2, &refpr3);


CI_low = (VR/ 2*&aart) * cinv(0.025,2*(&aart**2)/VR);
CI_high = (( VR + maxwt**2) / (2*(&aart+maxwt)))* cinv(0.975, 2*(&aart+maxwt)**2/(VR + maxwt**2));

put 'low =' CI_low;
put 'high = ' CI_high;

run;

%put &aart;

%mend confi;

%confi (aart=1000, dcount1=20, dcount2=70, dcount3= 10, spop1=3000, spop2=3000, spop3=200, refpr1=0.53468238, refpr2=0.30153350, refpr3=0.16378412)