<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: reciprocal problem of macro variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565702#M158865</link>
    <description>&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data try;
   x1=&amp;amp;HazardRate1.; 
   x2=&amp;amp;HazardRate2.;
   y1=1.0/(&amp;amp;HazardRate1.); 
   y2=1/(&amp;amp;HazardRate2.);
   z1=1/x1; 
   z2=1/x2;
RUN;&lt;/PRE&gt;
&lt;P&gt;or consider&lt;/P&gt;
&lt;PRE&gt;data example;
  x1 = 1/2/3;
  x2 =(1/2)/3;
  x3 = 1/(2/3);
run;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2019 22:13:00 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-06-12T22:13:00Z</dc:date>
    <item>
      <title>reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565690#M158857</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let HazardRated = log(2)/20;
%let HazardRate1 = log(2)/17;
%let HazardRate2 = log(2)/25;

data try;
        x1=&amp;amp;HazardRate1.; x2=&amp;amp;HazardRate2.;
        y1=1.0/&amp;amp;HazardRate1.; y2=1/&amp;amp;HazardRate2.;
        z1=1/x1; z2=1/x2;
RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I got :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 485px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30249i4901C09AC09D37CF/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why y1 ^= z1? y2 ^= z2? what is the problem? what happened to Y1 and Y2?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 21:07:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565690#M158857</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2019-06-12T21:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565691#M158858</link>
      <description>&lt;P&gt;Order of operations but for some reason still not matching your numbers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Y1 = 1.0/log(2)/20 = 1 / 0.693147 / 20 = 1.442695/20 = 0.072135&lt;/P&gt;
&lt;P&gt;Z1 = 1/ (log(2)/ 20) = 1 / (0.693147/20) = 1 / 0.03457 = 28.85&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56807"&gt;@fengyuwuzu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let HazardRated = log(2)/20;
%let HazardRate1 = log(2)/17;
%let HazardRate2 = log(2)/25;

data try;
        x1=&amp;amp;HazardRate1.; x2=&amp;amp;HazardRate2.;
        y1=1.0/&amp;amp;HazardRate1.; y2=1/&amp;amp;HazardRate2.;
        z1=1/x1; z2=1/x2;
RUN;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I got :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 485px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/30249i4901C09AC09D37CF/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;why y1 ^= z1? y2 ^= z2? what is the problem? what happened to Y1 and Y2?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 21:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565691#M158858</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-12T21:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565692#M158859</link>
      <description>&lt;P&gt;I'm guessing you want this, untested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let HazardRated = %sysevalf(%sysfunc(log(2))/20);
%let HazardRate1 = %sysevalf(%sysfunc(log(2))/17);
%let HazardRate2 = %sysevalf(%sysfunc(log(2))/25);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jun 2019 21:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565692#M158859</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-12T21:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565701#M158864</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data try;
        x1=&amp;amp;HazardRate1.; x2=&amp;amp;HazardRate2.;
        y1=1.0/(&amp;amp;HazardRate1.); y2=1/(&amp;amp;HazardRate2.);
        z1=1/x1; z2=1/x2;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jun 2019 22:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565701#M158864</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-06-12T22:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565702#M158865</link>
      <description>&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data try;
   x1=&amp;amp;HazardRate1.; 
   x2=&amp;amp;HazardRate2.;
   y1=1.0/(&amp;amp;HazardRate1.); 
   y2=1/(&amp;amp;HazardRate2.);
   z1=1/x1; 
   z2=1/x2;
RUN;&lt;/PRE&gt;
&lt;P&gt;or consider&lt;/P&gt;
&lt;PRE&gt;data example;
  x1 = 1/2/3;
  x2 =(1/2)/3;
  x3 = 1/(2/3);
run;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 22:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565702#M158865</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-12T22:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565704#M158866</link>
      <description>&lt;P&gt;Thank you so much. Now I understand.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 22:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565704#M158866</guid>
      <dc:creator>fengyuwuzu</dc:creator>
      <dc:date>2019-06-12T22:28:02Z</dc:date>
    </item>
    <item>
      <title>Re: reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565717#M158873</link>
      <description>&lt;P&gt;The macro variables just contain text.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for Y1 you are running:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;y1=1.0/log(2)/17;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But for Z1 because you calculated X1 already you are running this instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;z1=1.0 / ( log(2)/17 );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Jun 2019 00:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565717#M158873</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-13T00:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: reciprocal problem of macro variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565720#M158874</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;is correct that it is because of parenthesis.&lt;/P&gt;&lt;P&gt;You are getting the calculation of 1.0 divided by log(2) and then that result divided by 17.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I think it confuses people when your example contains three different variables and two examples.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let HazardRate1 = log(2)/17;

data try;
        x1=&amp;amp;HazardRate1.; 
        y1=1.0/&amp;amp;HazardRate1.; 
        y1_1=1.0/(&amp;amp;HazardRate1.);  *Force the calculation of this part first.;
        z1=1/x1; 
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 00:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/reciprocal-problem-of-macro-variables/m-p/565720#M158874</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-06-13T00:38:25Z</dc:date>
    </item>
  </channel>
</rss>

