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!

Squaring a macro variable

Status
Not open for further replies.

PetrOtahal

Technical User
Dec 3, 2007
12
AU
I have a problem when trying to square the &B macro variable in the following code:
Code:
data parmscalcs; 
  array _YSSurv{5};
  merge parms parmsmatrix; 
  retain B;
  B=B;
  if Level=1 then do; 
    B= 9 * &CumSurvFinal * (log(_YSSurv{1})+
         log(_YSSurv{2}) + log(_YSSurv{3}) +
         log(_YSSurv{4}) + log(_YSSurv{5}));
    call symput('B', B);
  end;
run;

data FinalCalc;
  merge covarmatrix parmscalcs AMatrix; [COLOR=red]
  Squared1= &B*&B;
  Squared2= &B**2; [/color]
run;

proc print data=FinalCalc; var Squared:; run;

The value of the &B macro variable is: -2.048898
Output looks like this:
Code:
        Obs    Squared1    Squared2
         1      4.19798    -4.19798

Can anyone explain why squaring with the **2 notation does
not produce the correct output??

Thanks,
Petr
 
Try rewriting that line like this:-
Code:
  Squared2= (&B)**2;

My suspicion is that SAS is processing the statement like
"-(2.048898**2)" rather than "(-2.048898)**2"
I played with it a little and putting in the brackets fixes it.
If you just type in
Code:
  Squared2 = -2.048898**2;
you get the same answer.

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

Part and Inventory Search

Sponsor

Back
Top