<?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: Extract file name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370738#M88543</link>
    <description>&lt;P&gt;When you use the FILENAME you need to actually store it, I don't see that in your code, but it doesn't look complete either....&lt;/P&gt;
&lt;P&gt;This is what you'd add and you should have a variable called sourceFile in your dataset. I don't even think fullFileName would be outputted to your dataset otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sourceFile = fullFileName;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 26 Jun 2017 20:05:27 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-06-26T20:05:27Z</dc:date>
    <item>
      <title>Extract file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370732#M88542</link>
      <description>&lt;P&gt;I have a very simple program that reads in the contents of all the .csv files in a Windows directory. That part of the program works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to add the file name to each record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem I have is the variable fullfilename contains only 'C:\Users' rather than the full name. I have verified this with PUT statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the log, SAS correctly identifies the full path and name and the proper data is imported but the ticker field (to wihich I tried to assign the parsed filename) is blank, as is the fullfilename field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Windows 10 and SAS 9.4 in Enterprise Guide&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data ticker_files;&lt;BR /&gt;infile 'c:\Users\tparrent\Documents\SandP 500 Stock History\daily\table_*.csv'&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;FILENAME=fullfilename&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;DELIMITER=','&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;FIRSTOBS=1;&lt;BR /&gt;put fullfilename;&lt;BR /&gt;&lt;BR /&gt;do until(last);&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;input dateint unknown open high low close volume;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;ticker = scan(scan(fullfilename,-1,'_'),1,'.');&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;output;&lt;BR /&gt;end;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 19:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370732#M88542</guid>
      <dc:creator>tparrent</dc:creator>
      <dc:date>2017-06-26T19:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370738#M88543</link>
      <description>&lt;P&gt;When you use the FILENAME you need to actually store it, I don't see that in your code, but it doesn't look complete either....&lt;/P&gt;
&lt;P&gt;This is what you'd add and you should have a variable called sourceFile in your dataset. I don't even think fullFileName would be outputted to your dataset otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sourceFile = fullFileName;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jun 2017 20:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370738#M88543</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-26T20:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370741#M88544</link>
      <description>&lt;P&gt;I tried your sugestions and sourceFileName still contains only 'C:\Users'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did post the entire code and it does run and import the data from the files&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 20:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370741#M88544</guid>
      <dc:creator>tparrent</dc:creator>
      <dc:date>2017-06-26T20:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370746#M88546</link>
      <description>&lt;P&gt;make sure to specify the length as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length fullFileName sourceName $256.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Jun 2017 20:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370746#M88546</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-26T20:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract file name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370748#M88547</link>
      <description>&lt;P&gt;LENGTH fullfilename $256.; did the trick!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much Reeza. I now understand something beyond the specific problem - don't get careless with variables!&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2017 20:29:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-file-name/m-p/370748#M88547</guid>
      <dc:creator>tparrent</dc:creator>
      <dc:date>2017-06-26T20:29:14Z</dc:date>
    </item>
  </channel>
</rss>

