<?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: SAS macro not resolving properly when value is numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233988#M42757</link>
    <description>&lt;P&gt;There are multiple issues with the code you've posted (like a blank between the % and the IF, or a dot between 2 and 3). If I just copy/past your code&amp;nbsp;into my environment and then run it I'm getting a syntax error and not what you describe. Below a code example of how the macro syntax for the logic needs to look like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options MINOPERATOR;
%global level;
%let level = 2;

%macro reports (tb=, exp=);
  %if &amp;amp;level. in (2 3) %then
    %do;
      %put TRUE;
    %end;
  %else %put FALSE;
%mend reports;

%reports ();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Nov 2015 11:43:43 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2015-11-10T11:43:43Z</dc:date>
    <item>
      <title>SAS macro not resolving properly when value is numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233984#M42756</link>
      <description>&lt;P&gt;I have the following code which doesn't run correctly when I run it through once. &amp;nbsp;If resubmitting the code, it works as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%global level;&lt;/P&gt;
&lt;P&gt;%let level = 2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro reports (tb=, exp=);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc export data = &amp;amp;tb.&lt;BR /&gt;outfile = "c:\test.xlsb"&lt;BR /&gt;dbms = excelcs replace label;&lt;BR /&gt;sheet = "Table &amp;amp;tb.";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;% if &amp;amp;level. in (2.3) then %do;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; proc export data = data2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; outfile = "&lt;/SPAN&gt;&lt;SPAN&gt;c:\test&lt;/SPAN&gt;&lt;SPAN&gt;.xlsb"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; dbms = excelcs replace label;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; sheet = "Table2";&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend reports;&lt;/P&gt;
&lt;P&gt;%reports (tb=data1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the first run, macro variable Level resolves to 2&amp;nbsp;but the %if condition is evaluated as False. &amp;nbsp;Running the code through a second time in the same session resolves it to True.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 10:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233984#M42756</guid>
      <dc:creator>kimdukes77</dc:creator>
      <dc:date>2015-11-10T10:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro not resolving properly when value is numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233988#M42757</link>
      <description>&lt;P&gt;There are multiple issues with the code you've posted (like a blank between the % and the IF, or a dot between 2 and 3). If I just copy/past your code&amp;nbsp;into my environment and then run it I'm getting a syntax error and not what you describe. Below a code example of how the macro syntax for the logic needs to look like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options MINOPERATOR;
%global level;
%let level = 2;

%macro reports (tb=, exp=);
  %if &amp;amp;level. in (2 3) %then
    %do;
      %put TRUE;
    %end;
  %else %put FALSE;
%mend reports;

%reports ();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 11:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233988#M42757</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-10T11:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro not resolving properly when value is numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233989#M42758</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, there are a few things wrong here straight off. &amp;nbsp;First, you don't want to be exporting to XLSB which is a XLS file with VBA enabled - i.e. it has a binary component. &amp;nbsp;I am not sure SAS can even export to that file format. &amp;nbsp;Next, this line of code is all wrong:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;% if &amp;amp;level. in (2.3) then %do;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;First, there is a space before the if which shouldn't be there, second in needs parameters separated by comma's not period's. &amp;nbsp;Thirdly macro variables are text, and hence the in should have quoted values, e.g. ("2","3"), also note, you may need to trim the macro variable, e.g.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%if %trim("&amp;amp;LEVEL.") in ("2","3") %then %do;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Note the %then rather than just then.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Perhaps it would just be easier to explain what you are trying to do, use sashelp.cars as an example file.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 11:45:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233989#M42758</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-10T11:45:28Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro not resolving properly when value is numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233992#M42759</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;On macro level everything is text so you don't need to quote the values.&lt;/P&gt;
&lt;P&gt;On macro level the separator between a value list is a blank and not a comma.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 12:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233992#M42759</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-10T12:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro not resolving properly when value is numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233993#M42760</link>
      <description>&lt;P&gt;Thanks to all who have responded.&amp;nbsp; Apologies for the many errors littering my posted code.&amp;nbsp; I am now using options MINOPERATOR and have removed the comma separating the values and all is working as exepcted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2015 12:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-not-resolving-properly-when-value-is-numeric/m-p/233993#M42760</guid>
      <dc:creator>kimdukes77</dc:creator>
      <dc:date>2015-11-10T12:08:53Z</dc:date>
    </item>
  </channel>
</rss>

