<?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: infile statement option memvar= in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637661#M189547</link>
    <description>&lt;P&gt;You took the code from &lt;A href="https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637655#M189545" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637655#M189545&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;What's the question?&lt;/P&gt;</description>
    <pubDate>Sun, 05 Apr 2020 09:01:28 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2020-04-05T09:01:28Z</dc:date>
    <item>
      <title>infile statement option memvar=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637655#M189545</link>
      <description>&lt;P&gt;To input multiple files , I need the stop statement in the data step when infile statement is used with the options memvar=mname to be listed one by one in a do loop as following.&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;length mname $ 32;&lt;BR /&gt;do mname = 'erase.dat', 'erase2.dat';&lt;BR /&gt;infile 'c:\mydir\tmp' memvar=mname end=done;&lt;BR /&gt;do while (^done);&lt;BR /&gt;input x;&lt;BR /&gt;put _all_;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;stop;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need not a stop statement when&amp;nbsp; the options memvar=memname to be set a blank as following&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;length memname $ 1024;&lt;BR /&gt;memname = ' ';&lt;BR /&gt;infile 'c:\mydir\tmp' memvar=memname end=done;&lt;BR /&gt;put memname=;&lt;BR /&gt;do while (^done);&lt;BR /&gt;input x;&lt;BR /&gt;put _all_;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Why?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 07:08:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637655#M189545</guid>
      <dc:creator>Steve1964</dc:creator>
      <dc:date>2020-04-05T07:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: infile statement option memvar=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637661#M189547</link>
      <description>&lt;P&gt;You took the code from &lt;A href="https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637655#M189545" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637655#M189545&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;What's the question?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 09:01:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637661#M189547</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-05T09:01:28Z</dc:date>
    </item>
    <item>
      <title>Re: infile statement option memvar=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637668#M189552</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/264961"&gt;@Steve1964&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the MEMVAR= variable (here: MEMNAME) is set to a missing value,&amp;nbsp;SAS iterates through the files in folder&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;c:\mydir\tmp&lt;/FONT&gt; and stops automatically after the last file has been processed. This is recognized when the value of MEMNAME (which is RETAINed by default) changes from the non-missing last file name to missing in the final iteration of the DATA step. You can see this if you insert another PUT statement before the assignment statement for MEMNAME:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put _n_= memname=;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;With non-missing values for the MEMVAR= variable, however, the rule is: A new file is opened when the value of the MEMVAR= variable &lt;EM&gt;changes&lt;/EM&gt;&amp;nbsp;(see &lt;A href="https://documentation.sas.com/?docsetId=lestmtsref&amp;amp;docsetTarget=n1rill4udj0tfun1fvce3j401plo.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;INFILE statement documentation&lt;/A&gt;). In your example this happens in each of the two iterations of the DO loop (i.e., MNAME changes from &lt;FONT face="courier new,courier"&gt;' '&lt;/FONT&gt; to &lt;FONT face="courier new,courier"&gt;'erase.dat'&lt;/FONT&gt; in the first iteration and from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'erase.dat'&lt;/FONT&gt; to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'erase2.dat'&lt;/FONT&gt; in the second). Without the STOP statement this would happen again when the DATA step started its second iteration: MNAME would change from&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'erase2.dat'&lt;/FONT&gt; to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'erase.dat'&lt;/FONT&gt;&amp;nbsp;and the DO loop would execute again (and again and again ...).&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 10:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637668#M189552</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-05T10:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: infile statement option memvar=</title>
      <link>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637692#M189568</link>
      <description>&lt;P&gt;Most data steps stop when they read past the end of the input (dataset or text file).&amp;nbsp; Your first code would never read past the end since it just keeps alternating between reading the two members.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also don't need the extra do loop in the second step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  length fname $ 1024;
  infile 'c:\mydir\tmp\*' filename=fname ;
  input ;
  if fname ne lag(fname) then _n_= fname= _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS: Does your filesystem really support filenames of 1024 bytes? I thought the Windows limit was 256.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2020 14:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/infile-statement-option-memvar/m-p/637692#M189568</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-05T14:40:40Z</dc:date>
    </item>
  </channel>
</rss>

