<?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: Importing multple excel file with a ist of diff names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548593#M152138</link>
    <description>Look into CALL EXECUTE instead of your last data step. Which step are you having issues with?</description>
    <pubDate>Thu, 04 Apr 2019 17:48:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-04-04T17:48:01Z</dc:date>
    <item>
      <title>Importing multple excel file with a ist of diff names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548578#M152127</link>
      <description>&lt;P&gt;I need help.&amp;nbsp; I am new to macros.&amp;nbsp; I need to create a macro that will import multiple excel files base on a list of names.&amp;nbsp; Below is my current code.&amp;nbsp; Please help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;dte = FEB2019;&lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*update monthly*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*Identify the current months FL files FILEDATE*/&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;filename&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; fref &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;pipe&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"ls /unixfolder/*&amp;amp;dte.*.xlsx"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; work.file_curr;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; fref;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;file&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; = scan(_infile_,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'/'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;path=scan(_infile_,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'.'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;/*List of current xls files to import*/&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; file_a(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=file );&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; file_curr;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;/*Macro to import files*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;options&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;mprint&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;symbolgen&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;mlogic&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Imp(all_mth);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; k=1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mth = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;all_mth, &amp;amp;k);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%while&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;mth"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NE &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;""&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;proc import DATAFILE=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"/unixlocation/&amp;amp;mth."&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dbms=xlsx&lt;/P&gt;
&lt;P&gt;out=outdata replace;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc append base=outdata _ALL data=outdata FORCE;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; k = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;k + 1);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mth = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%scan&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;all_mth, &amp;amp;k);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; check &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$200.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; file_a;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;check = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'%&lt;STRONG&gt;&lt;I&gt;imp&lt;/I&gt;&lt;/STRONG&gt;(file&lt;FONT color="#800080" face="Courier New"&gt;="strip(file));"&lt;/FONT&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 17:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548578#M152127</guid>
      <dc:creator>thomask23</dc:creator>
      <dc:date>2019-04-04T17:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multple excel file with a ist of diff names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548593#M152138</link>
      <description>Look into CALL EXECUTE instead of your last data step. Which step are you having issues with?</description>
      <pubDate>Thu, 04 Apr 2019 17:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548593#M152138</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-04T17:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multple excel file with a ist of diff names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548610#M152149</link>
      <description>The program works if I manually update the macro.  The problem is the naming conventions will change each month.  I am attempting to create a macro to execute it as a macro using a datafile.  however I do not know how to run a macro using a datafile.</description>
      <pubDate>Thu, 04 Apr 2019 18:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548610#M152149</guid>
      <dc:creator>thomask23</dc:creator>
      <dc:date>2019-04-04T18:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multple excel file with a ist of diff names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548614#M152151</link>
      <description>&lt;P&gt;Write a macro to read one file.&lt;/P&gt;
&lt;P&gt;Use the list of files to generate a separate call to the macro for each file you want to read.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 18:25:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548614#M152151</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-04T18:25:37Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multple excel file with a ist of diff names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548622#M152154</link>
      <description>&lt;P&gt;Be prepared to have problems with Proc Append following a Proc Import step.&lt;/P&gt;
&lt;P&gt;Each time you call Proc Import with XLSX files the procedure makes guesses about the variable types and lengths. In some cases the guesses may result in different variable types. So the append will fail because of mismatched data types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the length of a character variable changes you have a chance of having data truncated unless the very first file you import has the longest values for every variable that will ever occur.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another issue depending on how consistent the source of the XLSX files may be, is that your variables have a chance of changing names from file to file. Which can lead to missing values in the appended data because an Excel&amp;nbsp;column that had previously had a header like "Number of cases" changed to "Cases" or "# of Cases".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I once had a client that sent three files a week and they asked why we kept charging them programming fees to read the files. Even after explaining that changing the order of columns and/or&amp;nbsp;the column headers required that additional programming the client could not provide a consistent file layout.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 18:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548622#M152154</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-04T18:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multple excel file with a ist of diff names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548639#M152160</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/20274"&gt;@thomask23&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The program works if I manually update the macro. The problem is the naming conventions will change each month. I am attempting to create a macro to execute it as a macro using a datafile. however I do not know how to run a macro using a datafile.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Check the documentation for call execute. YOu can pass the filename to a macro and it will do it for you. I have a macro on my github page that does this, you can take a look at it here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The list_files macro part you have an easier solution so use that,but the data step and macro should be similar to what you need.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Import_all_files_one_type" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Import_all_files_one_type&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 20:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multple-excel-file-with-a-ist-of-diff-names/m-p/548639#M152160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-04T20:12:41Z</dc:date>
    </item>
  </channel>
</rss>

