<?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: Macro to import all Excel files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521453#M141487</link>
    <description>&lt;P&gt;You need to make up a rule for building the macro variable erk.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Dec 2018 13:39:30 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-12-14T13:39:30Z</dc:date>
    <item>
      <title>Macro to import all Excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521441#M141480</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I 'm trying to create a loop so that all the xlsx-files are imported. I notice that the code below is wrong but I don't know how to correct it the right way. I have 4 excelfiles to import. The result of this code is that the first excelfile is imported 4 times (and it overwrites itself each time). The result should be that 4 each excel file is imported once.&amp;nbsp;Each&amp;nbsp;excelfile has a different variable in its filename (ERK = 009, 090,091,777). Only the 009 is imported. Could anyone help me with this please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*macro to import a single excel*/&lt;BR /&gt;%macro import(input);&lt;/P&gt;&lt;P&gt;OPTIONS VALIDVARNAME=ANY;&lt;BR /&gt;PROC IMPORT OUT=work.B1B2_E&amp;amp;erk. (keep = N_BUD_AN ID_AGR TIT_N Source N2018)&lt;BR /&gt;DATAFILE= "&amp;amp;path\&amp;amp;input..xlsx"&lt;BR /&gt;DBMS=excelcs REPLACE;&lt;BR /&gt;RANGE="B1B2$"; /*to import the sheet completely*/&lt;BR /&gt;SCANTEXT=YES;&lt;BR /&gt;USEDATE=YES;&lt;BR /&gt;SCANTIME=YES;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;/*loop to import all the files*/&lt;BR /&gt;%macro Loadall;&lt;BR /&gt;%do i=1 %to &amp;amp;numobs;&lt;BR /&gt;%import(&amp;amp;&amp;amp;filein&amp;amp;i);&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;%loadall;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 13:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521441#M141480</guid>
      <dc:creator>Anneliesant</dc:creator>
      <dc:date>2018-12-14T13:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to import all Excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521443#M141482</link>
      <description>&lt;P&gt;Since you do not change &amp;amp;erk in the loop (or derive it somehow from &amp;amp;input), the dataset is always overwritten with the data from the latest import.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 13:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521443#M141482</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-14T13:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to import all Excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521449#M141486</link>
      <description>&lt;P&gt;How do I&amp;nbsp;write the code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before the macro this is written.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/*Each Excel file gets a variable, number*/&lt;BR /&gt;data _null_;&lt;BR /&gt;set mydata.deelnemerslijst end=endobs;/*end=variable --&amp;gt; at the last observation it starts counting*/&lt;BR /&gt;call symputx('fileIN'!!left(_n_),excel_file);/*takes the name and puts a number in front "n" (_n_ counts the lines --&amp;gt; this combination is named 'fileIN'*/&lt;BR /&gt;if endobs=1 then call symputx('numobs',_N_);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 13:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521449#M141486</guid>
      <dc:creator>Anneliesant</dc:creator>
      <dc:date>2018-12-14T13:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to import all Excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521453#M141487</link>
      <description>&lt;P&gt;You need to make up a rule for building the macro variable erk.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 13:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521453#M141487</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-14T13:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to import all Excel files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521467#M141492</link>
      <description>&lt;P&gt;There are many examples of this type on here, please use the search functionality:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;q=import+multiple+excel+files" target="_blank"&gt;https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;q=import+multiple+excel+files&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Dec 2018 14:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-import-all-Excel-files/m-p/521467#M141492</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-14T14:19:30Z</dc:date>
    </item>
  </channel>
</rss>

