<?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 Using FILENAME in an 'if' statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-FILENAME-in-an-if-statement/m-p/83184#M17953</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to set a file reference according to how a macro variable is set.&amp;nbsp; It appears as if SAS is ignoring my "if" blocks.&amp;nbsp; Here is some code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET DRIVE=M;&lt;/P&gt;&lt;P&gt;LIBNAME USEFILE "C:\";&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if ("&amp;amp;DRIVE" = 'M') then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; filename fileh 'this.txt';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;if ("&amp;amp;DRIVE" = 'S') then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; filename fileh 'that.txt';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;data test; infile fileh;&lt;/P&gt;&lt;P&gt;input test;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I try to run this the SAS code tries to open "that.txt".&amp;nbsp; Why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Apr 2012 18:54:16 GMT</pubDate>
    <dc:creator>WesBarris</dc:creator>
    <dc:date>2012-04-13T18:54:16Z</dc:date>
    <item>
      <title>Using FILENAME in an 'if' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FILENAME-in-an-if-statement/m-p/83184#M17953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to set a file reference according to how a macro variable is set.&amp;nbsp; It appears as if SAS is ignoring my "if" blocks.&amp;nbsp; Here is some code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%LET DRIVE=M;&lt;/P&gt;&lt;P&gt;LIBNAME USEFILE "C:\";&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;if ("&amp;amp;DRIVE" = 'M') then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; filename fileh 'this.txt';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;if ("&amp;amp;DRIVE" = 'S') then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; filename fileh 'that.txt';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;data test; infile fileh;&lt;/P&gt;&lt;P&gt;input test;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I try to run this the SAS code tries to open "that.txt".&amp;nbsp; Why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Apr 2012 18:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FILENAME-in-an-if-statement/m-p/83184#M17953</guid>
      <dc:creator>WesBarris</dc:creator>
      <dc:date>2012-04-13T18:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using FILENAME in an 'if' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FILENAME-in-an-if-statement/m-p/83185#M17954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would guess that the lines are executed before the if statements are seen.&amp;nbsp; Will it work correctly if you wrap it in a macro and then change your if statements to %if statements?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Apr 2012 19:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FILENAME-in-an-if-statement/m-p/83185#M17954</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-04-13T19:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using FILENAME in an 'if' statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-FILENAME-in-an-if-statement/m-p/83186#M17955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the FILENAME() function instead of the global filename statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Apr 2012 19:32:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-FILENAME-in-an-if-statement/m-p/83186#M17955</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-04-13T19:32:54Z</dc:date>
    </item>
  </channel>
</rss>

