<?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: Create if statements based on value of macro parameter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439427#M282416</link>
    <description>&lt;P&gt;How do these calculations depend on the value of &amp;amp;Response ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correct syntax depends on what is contained in the macro variables.&amp;nbsp; In particular, what is the value for &amp;amp;ClientCode ?&lt;/P&gt;</description>
    <pubDate>Thu, 22 Feb 2018 19:48:08 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-02-22T19:48:08Z</dc:date>
    <item>
      <title>Create if statements based on value of macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439418#M282415</link>
      <description>&lt;P&gt;I have a macro program that I've written that uses multiple parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One of these&amp;nbsp;parameters is the clients' name. The macro looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro&amp;nbsp; Program(&lt;BR /&gt;CampaignCode,&lt;BR /&gt;ClientCode,&lt;BR /&gt;Start,&lt;BR /&gt;End,&lt;BR /&gt;Response&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The commands that are called using the macro are pages and pages long but there is a certain place where I want to create a set of conditional statements for calculations based on the value of &amp;amp;&lt;SPAN&gt;ClientCode&lt;/SPAN&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically something like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.want;&lt;/P&gt;&lt;P&gt;set work.have;&lt;/P&gt;&lt;P&gt;if &amp;amp;&lt;SPAN&gt;ClientCode&lt;/SPAN&gt;&amp;nbsp;= "Client1" then Calculation = VAR1 +VAR2+VAR3;&lt;/P&gt;&lt;P&gt;else if &amp;amp;&lt;SPAN&gt;ClientCode&lt;/SPAN&gt;= "Client2" then Calculation = VAR1 + VAR3 + VAR4;&lt;/P&gt;&lt;P&gt;else if &amp;amp;&lt;SPAN&gt;ClientCode&lt;/SPAN&gt;&amp;nbsp;= "Client3" then Calculation = Var2 + VAR4 + VAR6;&lt;/P&gt;&lt;P&gt;.....;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that is not working correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like this is a relatively simple command I am trying to execute. Can someone show me the correct synthax?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 20:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439418#M282415</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2018-02-22T20:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create if statements based on value of macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439427#M282416</link>
      <description>&lt;P&gt;How do these calculations depend on the value of &amp;amp;Response ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The correct syntax depends on what is contained in the macro variables.&amp;nbsp; In particular, what is the value for &amp;amp;ClientCode ?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 19:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439427#M282416</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-22T19:48:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create if statements based on value of macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439431#M282417</link>
      <description>&lt;P&gt;The Value would be a string of 4 characters that are a code for the client.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some clients calculate their total budget based on different combinations of Variables&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 19:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439431#M282417</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2018-02-22T19:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create if statements based on value of macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439433#M282418</link>
      <description>&lt;P&gt;Ah...I see...that was a typo. It would not be dependent on Response...ONLY ClientCode.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 20:01:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439433#M282418</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2018-02-22T20:01:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create if statements based on value of macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439442#M282419</link>
      <description>&lt;P&gt;For that, you just need to add quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if "&amp;amp;ClientCode" = .....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They have to be double-quotes, not single-quotes.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 20:16:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439442#M282419</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-22T20:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create if statements based on value of macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439448#M282420</link>
      <description>&lt;P&gt;OMG I knew it was something simple. Was way overthinking it! Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 20:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439448#M282420</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2018-02-22T20:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create if statements based on value of macro parameter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439487#M282421</link>
      <description>&lt;P&gt;Not sure what RESPONSE has to do with your question as the code you posted is referencing the parameter CLIENTCODE instead.&lt;/P&gt;
&lt;P&gt;So code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.want;
  set work.have;
  if &amp;amp;ClientCode = "Client1" then Calculation = VAR1 +VAR2+VAR3;
  else if &amp;amp;ClientCode= "Client2" then Calculation = VAR1 + VAR3 + VAR4;
  else if &amp;amp;ClientCode = "Client3" then Calculation = Var2 + VAR4 + VAR6;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Will work you you set CLIENTCODE equal to something that evaluates to a character string.&amp;nbsp; So you could call it with a string literal.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%program(clientcode="Client2",...)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could call it with the name of a character variable that is in the HAVE dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%program(clientcode=Client_Id,...)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or even a function call that can run in the generated IF statement as long it the result is a character string that the IF statement can compare to the literal character values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Feb 2018 21:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-if-statements-based-on-value-of-macro-parameter/m-p/439487#M282421</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-22T21:53:06Z</dc:date>
    </item>
  </channel>
</rss>

