<?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: Add Excel File Name as Variable When Importing Multiple Excel Files in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-Excel-File-Name-as-Variable-When-Importing-Multiple-Excel/m-p/764955#M39446</link>
    <description>&lt;P&gt;Hi PhilC,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks I will let you know how it works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Aug 2021 22:09:58 GMT</pubDate>
    <dc:creator>ncorbett</dc:creator>
    <dc:date>2021-08-30T22:09:58Z</dc:date>
    <item>
      <title>Add Excel File Name as Variable When Importing Multiple Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-Excel-File-Name-as-Variable-When-Importing-Multiple-Excel/m-p/764206#M39406</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;New to SAS here!&lt;/P&gt;&lt;P&gt;I have a folder in which I will be dropping Excel Files (.xls) files. This is the format in which they come to me. The files have a date name. They will like this 08262021.xls.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I am trying to add a variable called "Date_Ordered", and for each line of each file add the name of the file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've searched the depths of the internet to try to find a code that will do this, but I don't see anyone out there posting it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I've got so far, which will import each file:&lt;/P&gt;&lt;P&gt;PROC IMPORT OUT= PROMO.CONNECTRAW DATAFILE=&lt;BR /&gt;"\\KTCHQF1\PARTHOME\PARTS SALES &amp;amp; MARKETING\PROMO TRACKER\CONNECT\2021\RAW DATA\*.xls"&lt;BR /&gt;DBMS=XLS REPLACE;&lt;BR /&gt;NAMEROW=4;&lt;BR /&gt;DATAROW=5;&lt;BR /&gt;SHEET="PARTS REPORT";&lt;BR /&gt;getnames=no;&lt;/P&gt;&lt;P&gt;(what i want to add is:&lt;/P&gt;&lt;P&gt;Variable name is Order_Date and for each line of each file, give me the File name)&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know what I can do to add a variable that will give me the file name for each line that I'm importing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've attached sample data, so when I import this file, I want under Order_Date, the data for each line from this file to say 08252021.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if more info or clarification is needed. OR if there is already something out there that can help me. And thank you for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Aug 2021 14:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-Excel-File-Name-as-Variable-When-Importing-Multiple-Excel/m-p/764206#M39406</guid>
      <dc:creator>ncorbett</dc:creator>
      <dc:date>2021-08-26T14:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Add Excel File Name as Variable When Importing Multiple Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-Excel-File-Name-as-Variable-When-Importing-Multiple-Excel/m-p/764432#M39416</link>
      <description>&lt;P&gt;I think you should think about performing multiple PROC IMPORTS, one for each Excel file.&amp;nbsp; Our user &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; has an excellent solution that you can template.&amp;nbsp; First he shows us away to read the filenames in the folder.&amp;nbsp; See the first part of the code here.&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/macro-to-read-all-files-together/m-p/181822/highlight/true#M13916" target="_blank"&gt;Solved: Re: macro to read all files together - SAS Support Communities&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then using the same technique as Tom, adapt your PROC IMPORT code into Tom's second part, as well as the code to add the columns.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are many ways to skin this cat, mind you.&amp;nbsp; I tend to use DOSUBL or CALL EXECUTE in the second part, Tomato-Tomaato.&amp;nbsp; This is another level of programming, writing programs to write programs.&amp;nbsp; Good luck.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Aug 2021 11:54:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-Excel-File-Name-as-Variable-When-Importing-Multiple-Excel/m-p/764432#M39416</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-08-27T11:54:22Z</dc:date>
    </item>
    <item>
      <title>Re: Add Excel File Name as Variable When Importing Multiple Excel Files</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-Excel-File-Name-as-Variable-When-Importing-Multiple-Excel/m-p/764955#M39446</link>
      <description>&lt;P&gt;Hi PhilC,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks I will let you know how it works!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 22:09:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Add-Excel-File-Name-as-Variable-When-Importing-Multiple-Excel/m-p/764955#M39446</guid>
      <dc:creator>ncorbett</dc:creator>
      <dc:date>2021-08-30T22:09:58Z</dc:date>
    </item>
  </channel>
</rss>

