%let HazardRated = log(2)/20;
%let HazardRate1 = log(2)/17;
%let HazardRate2 = log(2)/25;
data try;
x1=&HazardRate1.; x2=&HazardRate2.;
y1=1.0/&HazardRate1.; y2=1/&HazardRate2.;
z1=1/x1; z2=1/x2;
RUN;
I got :
why y1 ^= z1? y2 ^= z2? what is the problem? what happened to Y1 and Y2?
Order of operations but for some reason still not matching your numbers.
Y1 = 1.0/log(2)/20 = 1 / 0.693147 / 20 = 1.442695/20 = 0.072135
Z1 = 1/ (log(2)/ 20) = 1 / (0.693147/20) = 1 / 0.03457 = 28.85
@fengyuwuzu wrote:
%let HazardRated = log(2)/20; %let HazardRate1 = log(2)/17; %let HazardRate2 = log(2)/25; data try; x1=&HazardRate1.; x2=&HazardRate2.; y1=1.0/&HazardRate1.; y2=1/&HazardRate2.; z1=1/x1; z2=1/x2; RUN;
I got :
why y1 ^= z1? y2 ^= z2? what is the problem? what happened to Y1 and Y2?
I'm guessing you want this, untested:
%let HazardRated = %sysevalf(%sysfunc(log(2))/20);
%let HazardRate1 = %sysevalf(%sysfunc(log(2))/17);
%let HazardRate2 = %sysevalf(%sysfunc(log(2))/25);
Thank you so much. Now I understand.
data try;
x1=&HazardRate1.; x2=&HazardRate2.;
y1=1.0/(&HazardRate1.); y2=1/(&HazardRate2.);
z1=1/x1; z2=1/x2;
RUN;
Consider:
data try; x1=&HazardRate1.; x2=&HazardRate2.; y1=1.0/(&HazardRate1.); y2=1/(&HazardRate2.); z1=1/x1; z2=1/x2; RUN;
or consider
data example; x1 = 1/2/3; x2 =(1/2)/3; x3 = 1/(2/3); run;
when you have multiple operators with the same level of priority, such as division, and no parentheses to control order the evaluation is done from left to right.
So your code is equivalent to X1, which evaluates in the order indicated by X2 in my Example data set. The order you likely intended is the X3 version.
The macro variables just contain text.
So for Y1 you are running:
y1=1.0/log(2)/17;
But for Z1 because you calculated X1 already you are running this instead.
z1=1.0 / ( log(2)/17 );
@Reeza is correct that it is because of parenthesis.
You are getting the calculation of 1.0 divided by log(2) and then that result divided by 17.
Also, I think it confuses people when your example contains three different variables and two examples.
%let HazardRate1 = log(2)/17;
data try;
x1=&HazardRate1.;
y1=1.0/&HazardRate1.;
y1_1=1.0/(&HazardRate1.); *Force the calculation of this part first.;
z1=1/x1;
RUN;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.