<?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: IMPORT all excel files in a folder in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188602#M265881</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%macro &amp;lt;macroname&amp;gt; is the beginning of the macro&lt;/P&gt;&lt;P&gt;%mend is the end of the macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All that use in between %macro and %mend is the what you want the macro to run&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* first step of the macro xls2sas*/&lt;/P&gt;&lt;P&gt;%macro xls2sas(folder=&lt;/P&gt;&lt;P&gt;,subfd=Y&lt;/P&gt;&lt;P&gt;,exclfd=&lt;/P&gt;&lt;P&gt;,startrow=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and %mend is where the macro for xls2sas ends&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The next step is to call the macro and this is how you call it.&lt;/P&gt;&lt;P&gt;%xls2sas&lt;/P&gt;&lt;P&gt;(folder=&lt;/P&gt;&lt;P&gt;,subfd=Y&lt;/P&gt;&lt;P&gt;,exclfd=&lt;/P&gt;&lt;P&gt;,startrow=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did this help?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Sep 2014 20:49:09 GMT</pubDate>
    <dc:creator>Hima</dc:creator>
    <dc:date>2014-09-05T20:49:09Z</dc:date>
    <item>
      <title>IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188597#M265876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Does anyone have code that will import all excel files (.xlsx) in a folder regardless of the name of the file?&lt;/P&gt;&lt;P&gt;All files have one sheet named ALL_INJ.&lt;/P&gt;&lt;P&gt;Also, is it possible to capture the name of the excel file in a macro or in each SAS dataset that is created?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Sep 2014 18:58:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188597#M265876</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2014-09-05T18:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188598#M265877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://www.pharmasug.org/proceedings/2011/CC/PharmaSUG-2011-CC10.pdf" title="http://www.pharmasug.org/proceedings/2011/CC/PharmaSUG-2011-CC10.pdf"&gt;http://www.pharmasug.org/proceedings/2011/CC/PharmaSUG-2011-CC10.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Sep 2014 19:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188598#M265877</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2014-09-05T19:05:57Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188599#M265878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Where can I find the code for the macro (ie %xls2sas)?&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Sep 2014 19:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188599#M265878</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2014-09-05T19:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188600#M265879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%macro xls2sas(folder=&lt;/P&gt;&lt;P&gt;,subfd=Y&lt;/P&gt;&lt;P&gt;,exclfd=&lt;/P&gt;&lt;P&gt;,startrow=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt; font-family: Courier New;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;You need to fill in those parameters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Sep 2014 19:23:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188600#M265879</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2014-09-05T19:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188601#M265880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't I need the SAS macro code in order to run the macro xls2sas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Sep 2014 20:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188601#M265880</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2014-09-05T20:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188602#M265881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;%macro &amp;lt;macroname&amp;gt; is the beginning of the macro&lt;/P&gt;&lt;P&gt;%mend is the end of the macro&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All that use in between %macro and %mend is the what you want the macro to run&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* first step of the macro xls2sas*/&lt;/P&gt;&lt;P&gt;%macro xls2sas(folder=&lt;/P&gt;&lt;P&gt;,subfd=Y&lt;/P&gt;&lt;P&gt;,exclfd=&lt;/P&gt;&lt;P&gt;,startrow=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and %mend is where the macro for xls2sas ends&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The next step is to call the macro and this is how you call it.&lt;/P&gt;&lt;P&gt;%xls2sas&lt;/P&gt;&lt;P&gt;(folder=&lt;/P&gt;&lt;P&gt;,subfd=Y&lt;/P&gt;&lt;P&gt;,exclfd=&lt;/P&gt;&lt;P&gt;,startrow=);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did this help?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Sep 2014 20:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188602#M265881</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2014-09-05T20:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188603#M265882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Isn't there macro code to download so the macro can be run?&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/mwiki/images/e/ee/For.sas" title="http://www.sascommunity.org/mwiki/images/e/ee/For.sas"&gt;http://www.sascommunity.org/mwiki/images/e/ee/For.sas&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Sep 2014 20:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/188603#M265882</guid>
      <dc:creator>gzr2mz39</dc:creator>
      <dc:date>2014-09-05T20:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/794368#M265883</link>
      <description>&lt;P&gt;The %xls2sas macro from the article referenced above is INCOMPLETE.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The authors explain, amongst other things, that they make use of SAS functions such as DREAD.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the macro itself does not have this line of code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the %macro as I was trying to test it. Perhaps someone can tell me where I am wrong or what I am missing.&lt;/P&gt;&lt;P&gt;%macro dt_xls2sas (folder= ,subfd=Y ,exclfd= ,startrow=);&lt;/P&gt;&lt;P&gt;*- Local macro variable declaration;&lt;/P&gt;&lt;P&gt;%local _j _cnt _dsid _i _num _s_ext _s_name _filename _rc;&lt;/P&gt;&lt;P&gt;%let _rc=%qsysfunc(filename(filrf,&amp;amp;folder));&lt;BR /&gt;%if &amp;amp;_rc=0 %then&lt;BR /&gt;%do;&lt;/P&gt;&lt;P&gt;*- Open the folders;&lt;/P&gt;&lt;P&gt;%let _dsid=%sysfunc(dopen(&amp;amp;filrf));&lt;BR /&gt;%if &amp;amp;_dsid&amp;gt;0 %then&lt;BR /&gt;%do;&lt;/P&gt;&lt;P&gt;*- Ge the number of folders;&lt;/P&gt;&lt;P&gt;%let _num=%sysfunc(dnum(&amp;amp;_dsid));&lt;BR /&gt;%do _i=1 %to &amp;amp;_num;&lt;BR /&gt;&lt;BR /&gt;%let _filename=%sysfunc(dread(&amp;amp;_dsid.,&amp;amp;_i.));&lt;BR /&gt;%put _filename=;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*- Check if the file extension is XLS. If so, open Excel workbook and read in the multi-sheets or named ranges;&lt;/P&gt;&lt;P&gt;%if %upcase(&amp;amp;_s_ext)=XLS %then&lt;BR /&gt;%do;&lt;BR /&gt;libname excellib excel "&amp;amp;folder\&amp;amp;_filename";&lt;BR /&gt;libname excellib clear;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;*- If the file extension resolves to NULL, check if the read subfolder flag is Y and also it is not;&lt;BR /&gt;*- in the exclusion folder list. If so, call %xls2sas to open the subfolder and Excel files under it;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%else %if %scan(&amp;amp;_filename, 2, .)= and &amp;amp;subfd=Y and&lt;BR /&gt;%qsysfunc(indexw(&amp;amp;exclfd,&amp;amp;_filename))=0 %then&lt;BR /&gt;%do;&lt;BR /&gt;%dt_xls2sas(folder=&amp;amp;folder\&amp;amp;_filename,&lt;BR /&gt;subfd=&amp;amp;subfd,&lt;BR /&gt;exclfd=&amp;amp;exclfd,&lt;BR /&gt;startrow=&amp;amp;startrow)&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend dt_xls2sas;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Feb 2022 23:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/794368#M265883</guid>
      <dc:creator>ruysolo</dc:creator>
      <dc:date>2022-02-03T23:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/794388#M265884</link>
      <description>&lt;P&gt;Split the problem into pieces.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Make a dataset with the list of files.&amp;nbsp; You can use DOPEN() and DREAD() if you have to , but do it in a data step and not in macro code.&amp;nbsp; This will not only be a lot easier to code and debug but you end up with something you can actual use to track your progress.&lt;/P&gt;
&lt;P&gt;2) Make a program that can convert one file into a dataset.&amp;nbsp; Do it first as hardcode for one specific file so you know how to generate the code. Figure out what part changes.&amp;nbsp; It might help to convert it to a macro that takes as input the parts that change.&amp;nbsp; You might&amp;nbsp;include a method for adding a column it you need it to indicate which file the data come from.&amp;nbsp; &amp;nbsp;But you might also do that later when you try to combine the files.&amp;nbsp; If you are reading from EXCEL files then you probably will HAVE to keep the data from each sheet in a different dataset because the lengths of character variables will vary based on the particular values in that particular sheet.&amp;nbsp; That is just part of "joy" of working with a tool that is designed for exploration of data and not management of data.&lt;/P&gt;
&lt;P&gt;3) Use the dataset from step1 to generate code to import all of the files (at least the ones you want).&amp;nbsp; You could use CALL EXECUTE() or just PUT the code to a file and use %INCLUDE to run it.&amp;nbsp; I prefer the latter because it is so much easier to debug.&amp;nbsp; Especially if you are running interactively (or even pseudo interactively using SAS/Studio or Enterprise Guide) where you can examine the results of one step before moving onto the nest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 03:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/794388#M265884</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-04T03:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: IMPORT all excel files in a folder</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/794403#M265885</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%if %upcase(&amp;amp;_s_ext)=XLS %then&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You use the macro variable in the comparison, but you never set it to a value, so this condition will always be false.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 06:23:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IMPORT-all-excel-files-in-a-folder/m-p/794403#M265885</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-04T06:23:10Z</dc:date>
    </item>
  </channel>
</rss>

