<?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: Extracting a portion of a text file name to incorporate into the file itself in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-a-portion-of-a-text-file-name-to-incorporate-into-the/m-p/860077#M339781</link>
    <description>&lt;P&gt;Two things to keep in mind:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the variable created by the FILENAME= option is temporary and not included in the dataset; you need to create another one for storage in the dataset&lt;/LI&gt;
&lt;LI&gt;define the length of the variable(s) before the INFILE statement, so they don't default to $8&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Wed, 22 Feb 2023 06:05:03 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-02-22T06:05:03Z</dc:date>
    <item>
      <title>Extracting a portion of a text file name to incorporate into the file itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-a-portion-of-a-text-file-name-to-incorporate-into-the/m-p/859999#M339743</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;
&lt;P&gt;I'm pulling in several text files (up to 100) stored on our SAS server that has a date on the file name that I need to incorporate into the imported file itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: From the infile statement below I need to extract the 20230221 portion of the file name and insert it as a variable into the file I'm creating. There is no rhyme or reason for the date sequence, just the date it's run on.&lt;/P&gt;
&lt;P&gt;If I knew how to extract that date I could put it into a do-loop and run it that way. But the question is: how do I extract that file the file name for 100 text files?&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;INFILE '/sasdata/US/Sales/Weekly_Sales_&lt;STRONG&gt;20230221&lt;/STRONG&gt;.txt' &lt;BR /&gt;LRECL=32767&lt;BR /&gt;FIRSTOBS=2&lt;BR /&gt;ENCODING="LATIN1"&lt;BR /&gt;DLM='09'x&lt;BR /&gt;MISSOVER&lt;BR /&gt;DSD ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 20:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-a-portion-of-a-text-file-name-to-incorporate-into-the/m-p/859999#M339743</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2023-02-21T20:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting a portion of a text file name to incorporate into the file itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-a-portion-of-a-text-file-name-to-incorporate-into-the/m-p/860055#M339773</link>
      <description>&lt;P&gt;How are you creating the INFILE statement in the first place? Is it maintained manually or is it generated automatically? In any case just add the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n1rill4udj0tfun1fvce3j401plo.htm" target="_blank" rel="noopener"&gt;FILENAME&lt;/A&gt; option on your INFILE statement and the variable you specify will contain the name of the file you are reading:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;INFILE '/sasdata/US/Sales/Weekly_Sales_20230221.txt'
FILENAME = MyFile
LRECL=32767
FIRSTOBS=2
ENCODING="LATIN1"
DLM='09'x
MISSOVER
DSD ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2023 00:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-a-portion-of-a-text-file-name-to-incorporate-into-the/m-p/860055#M339773</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-22T00:49:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting a portion of a text file name to incorporate into the file itself</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-a-portion-of-a-text-file-name-to-incorporate-into-the/m-p/860077#M339781</link>
      <description>&lt;P&gt;Two things to keep in mind:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;the variable created by the FILENAME= option is temporary and not included in the dataset; you need to create another one for storage in the dataset&lt;/LI&gt;
&lt;LI&gt;define the length of the variable(s) before the INFILE statement, so they don't default to $8&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 22 Feb 2023 06:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-a-portion-of-a-text-file-name-to-incorporate-into-the/m-p/860077#M339781</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-22T06:05:03Z</dc:date>
    </item>
  </channel>
</rss>

