<?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: Defining macro variable by cases in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284055#M19446</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are attempting to evaluate arithmetic expressions represented by values of macro variables, you need to use the macro function %SYSEVALF (&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206831.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206831.htm&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
    <pubDate>Wed, 13 Jul 2016 14:53:40 GMT</pubDate>
    <dc:creator>JohnSAScom</dc:creator>
    <dc:date>2016-07-13T14:53:40Z</dc:date>
    <item>
      <title>Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284048#M19443</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;I'm on SAS EG 5.1.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;One possible way to define variables by cases is, for instance,&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Variable=2*(Statement 1)+3*(Neg of Statement 1);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;What is this called? I'd like to read about it, but I don't know what words to search for.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Now please consider the following code.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;%MACRO CYCLE;
	%DO A=1 %TO 2;
	%PUT &amp;amp;A.;
	%LET B=0.636805089257504*(&amp;amp;A.=1)+0.656423671305948*(&amp;amp;A.=2);
	%PUT &amp;amp;B.;
	%END;
%MEND; %CYCLE;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;On the log I find this:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;1
0.636805089257504*(1=1)+0.656423671305948*(1=2)
2
0.636805089257504*(2=1)+0.656423671305948*(2=2)&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;I expected it to be&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;1
0.636805089257504
2
0.656423671305948&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;What am I missing?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Finally, for my actual question, regarding the second block of code, I'm trying to sue the variable B within a Data-Step and it's obvious from some simple computations that B isn't getting the value I expected it to get. In fact, it gets a value that doesn't seem at all related with any of the coefficients used above.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;I worked around this by defining B withing the Data-Step, but this is seems crass.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Can you explain to me why isn't my macro variable B working properly and how can I fix it?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;Thanks.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 14:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284048#M19443</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-07-13T14:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284052#M19444</link>
      <description>Hi&lt;BR /&gt;All macro variables are character, there are no numeric variables.&lt;BR /&gt;If you want to perform a calculation use the %eval macro function, for example %eval(0.636805089257504*(&amp;amp;A.=1)+0.656423671305948*(&amp;amp;A.=2));&lt;BR /&gt;This should give you the expected results&lt;BR /&gt;Cheers&lt;BR /&gt;Chris</description>
      <pubDate>Wed, 13 Jul 2016 14:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284052#M19444</guid>
      <dc:creator>rivieralad</dc:creator>
      <dc:date>2016-07-13T14:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284053#M19445</link>
      <description>&lt;P&gt;1. This is logic, base math, and the fact that true/false are represented as 1/0. I don't know that that's documents anywhere but you could try searching for Boolean operators.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. If you want to evaluate an expression while assigning macro variables you need to use %eval and/or %sysevalf. One deals with integer arithmetic and the other with floating point arithmetic.&lt;/P&gt;
&lt;P&gt;How is SAS supposed to know if you want that as text or if you want the expression resolved? By default it treats it as text and you can override this by using the macro functions mentioned above.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 14:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284053#M19445</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-13T14:50:58Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284055#M19446</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are attempting to evaluate arithmetic expressions represented by values of macro variables, you need to use the macro function %SYSEVALF (&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206831.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000206831.htm&lt;/A&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 14:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284055#M19446</guid>
      <dc:creator>JohnSAScom</dc:creator>
      <dc:date>2016-07-13T14:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284064#M19447</link>
      <description>&lt;P&gt;Even though it's good to understand the processes and how the macro processor works ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within a DATA step you are probably getting improper values because of the DATA step's order of operations.&amp;nbsp; When you substitute the very long version of &amp;amp;B in a DATA step, the order of operations is likely wrong.&amp;nbsp; A simple way to solve this is to add parentheses.&amp;nbsp; Instead of:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let B= ...;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let B=(...);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just include the same logic as you are now but add parentheses.&amp;nbsp; That will force the DATA step to perform math on the longer expression first, before using it in further calculations.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284064#M19447</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-13T15:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284087#M19448</link>
      <description>Apparently I need to use %SYSEVALF. Using %EVAL I get the following error.&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:&lt;BR /&gt;0.636805089257504*(1=1)+0.656423671305948*(1=2)&lt;BR /&gt;ERROR: The macro CYCLE will stop executing.</description>
      <pubDate>Wed, 13 Jul 2016 15:34:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284087#M19448</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-07-13T15:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284088#M19449</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I asked because I'm pretty sure I've read about it on the help documentation and I'd like to see what's on that article.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To me it's not obvious that a statement and its truth value are one and the same. In fact, being a mathematician, conceptually they are two different things and before you told me this it didn't cross my mind that it would all be the same for SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't know macro variables are text by default, thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284088#M19449</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-07-13T15:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284089#M19450</link>
      <description>&lt;P&gt;Will do, thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 15:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284089#M19450</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-07-13T15:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284093#M19451</link>
      <description>&lt;P&gt;Programming unfortunately is not mathematics as we get to deal with the "rules" established by the program designers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Numeric to true and false work two slightly different ways.&lt;/P&gt;
&lt;P&gt;When SAS assigns the value to a comparison it will always use 1 for true and 0 for false.&lt;/P&gt;
&lt;P&gt;But if you have a numeric variable you can use it as a boolean. If the value is not missing and not 0 SAS will treat it as true, otherwise false.&lt;/P&gt;
&lt;P&gt;Please see the results from this brief program as a demonstration.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   do x= -1 to 3, ., .5;
      if (x) then put x " is true";
      else put x " is false";
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 21:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284093#M19451</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-13T21:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284151#M19458</link>
      <description>&lt;P&gt;Instructive. Thank you very much.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 18:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284151#M19458</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-07-13T18:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284155#M19459</link>
      <description>&lt;P&gt;See expressions section in the documentation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p05cxkf6p0fnifn181pu6jj9r0y6.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p05cxkf6p0fnifn181pu6jj9r0y6.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 18:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284155#M19459</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-13T18:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284156#M19460</link>
      <description>&lt;P&gt;You should check how SAS treats positive/negative/0 values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is true/false is good to know.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jul 2016 18:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/284156#M19460</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-13T18:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Defining macro variable by cases</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/286071#M19567</link>
      <description>&lt;P&gt;I thought I had replied, I just noticed I didn't.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for this lesson.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2016 10:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Defining-macro-variable-by-cases/m-p/286071#M19567</guid>
      <dc:creator>sleretrano</dc:creator>
      <dc:date>2016-07-21T10:19:27Z</dc:date>
    </item>
  </channel>
</rss>

