<?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 multiple Excel sheets and merging them into one with a macro - SAS 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452887#M114344</link>
    <description>&lt;P&gt;You might discuss with whoever is creating these files if another file creation option such as CSV (or other delimited text file format) would be practical. The process might be creating Excel files because "every one wants Excel" is a default thought pattern for some. Even if some users of this data want the spreadsheet format it may well be possible to have interchange data provided in another form for you, especially if these files are created by another program (especially a data base). An agreed upon file format for each of these files, a data step to read each and the daily requirement becomes changing input file names and output data set names (if needed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option to consider if this data is being created by a different data base is that SAS provides a number of ways to connect directly to many databases. Perhaps you might be better off with a SAS/ACCESS and direct connections to the data source. If the data comes from a database it is almost certain that data has consistent data properties.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Document how much time it takes to adjust everything for ONE day of data. Extrapolate that work load over a 4 or 6 month period. Talk to your supervisor about the total cost in man hours and resources the current data process involving Excel will entail as well as delays in response to questions based on this daily data from having to "fix" things daily. You might be surprised at the amount of management support might appear when $$$$ are pointed out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For what it may be worth: changing the informat property for a variable after it has been imported is basically lying to yourself and others. I really wouldn't want to explain why a variable has an informat of $60. when the actual length is 6&amp;nbsp;&amp;nbsp;or 120 characters.&lt;/P&gt;</description>
    <pubDate>Tue, 10 Apr 2018 16:42:04 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-04-10T16:42:04Z</dc:date>
    <item>
      <title>Importing multiple Excel sheets and merging them into one with a macro - SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452738#M114282</link>
      <description>&lt;P&gt;SAS 9.4. I want to import multiple&amp;nbsp;Excel files (approx 20 daily files)&amp;nbsp;into SAS and merge them into 1 SAS file. I want to do this using macro. My issue arises when&amp;nbsp;SAS starts to import the first file with no data because some files are empty.&amp;nbsp;It converts my numeric variables into character. I have tried to modify my variables into both numeric/character&amp;nbsp;with no luck. I have attached&amp;nbsp;example data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get below error msg:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: The import data set has 3 observations and 19 variables.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: DER.20180301. data set was successfully created.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: PROCEDURE IMPORT used (Total process time):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;real time 0.14 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;cpu time 0.03 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: Table DER.'20180301.'n has been modified, with 19 columns.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;real time 0.08 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;cpu time 0.00 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: The import data set has 0 observations and 19 variables.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: DER.20180302. data set was successfully created.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: PROCEDURE IMPORT used (Total process time):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;real time 0.18 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;cpu time 0.06 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ERROR: Character column ID_2 requires a character format specification.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ERROR: Character column ID_2 requires a character informat specification.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: Table DER.'20180302.'n has been modified, with 19 columns.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;real time 0.11 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#3366ff"&gt;cpu time 0.00 seconds&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ERROR: Value 3 on the SELECT clause does not match the data type of the corresponding column&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;listed after the INSERT table name.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ERROR: Value 9 on the SELECT clause does not match the data type of the corresponding column&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;listed after the INSERT table name.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;ERROR: Value 11 on the SELECT clause does not match the data type of the corresponding column&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#993300"&gt;listed after the INSERT table name.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;My code is:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;ods&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;html&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;newfile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;proc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%Let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Year = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(date(),year4.);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%Let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; LastMonth = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(putn(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(intnx(month,&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(today()),-1, same)),monname.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/* Find and import relevant excel workbooks into SAS */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;libname&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; DER &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"I:\Dat\DER"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; path = I:\Dat\3950MFI;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;filename&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; folder &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"&amp;amp;path\Control\&amp;amp;Year\&amp;amp;LastMonth"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;options&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; validmemname=extend; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="2"&gt;/* to allow non-standard dataset names */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/* Making a list of all excel workbooks into table FilesInFolder */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; FilesInFolder;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; File $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;300&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;List = dopen(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'folder'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Line = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; dnum(List);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;File = trim(dread(List,Line));&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/* Ascending order for varibale File in table FilesInFolder */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; = FilesInFolder;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; File; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000" face="Courier New" size="2"&gt;/* Creating global macro variables */&lt;/FONT&gt; &lt;FONT color="#008000" face="Courier New" size="2"&gt;/* not local */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;_NULL_&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; FilesInFolder &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=final;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symput(cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'File'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;, _N_), trim(File)); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symput(cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'Name'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;, _N_), trim(nliteral(substr(File,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;,min(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;32&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;, length(File)-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;)))));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; final &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; symputx(trim(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'Total'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;), _N_); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &lt;STRONG&gt;&lt;I&gt;loop&lt;/I&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/* Imports all workbooks specified in variable List from table FilesInFolder and saves them as datasets in Library DER */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%to&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &amp;amp;Total; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;proc import datafile=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"&amp;amp;path\Control\&amp;amp;Year\&amp;amp;LastMonth\&amp;amp;&amp;amp;File&amp;amp;i"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;out=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DER.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;&amp;amp;Name&amp;amp;i &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;DBMS=xlsx REPLACE;&lt;/P&gt;&lt;P&gt;sheet=DER;&lt;/P&gt;&lt;P&gt;getnames=yes;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;alter table &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DER.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;&amp;amp;Name&amp;amp;i&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;modify COMMENT char(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;60&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) format=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; informat=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;modify ID_2 char(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;60&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) format=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; informat=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;modify ID_3 char(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;60&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) format=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; informat=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;modify PRE_THEM_ID (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;60&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) format=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; informat=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;$60.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/* Inserts all datasets from above into the first dataset from the Library */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &amp;amp;i gt &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;insert into &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DER.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;Name1 select * from &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DER.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;&amp;amp;Name&amp;amp;i;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;proc export data=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DER.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;Name1 outfile= &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"I:\Dat\3950MFI\OUT\DER_&amp;amp;LastMonth..xlsx"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;DBMS=xlsx REPLACE;&lt;/P&gt;&lt;P&gt;sheet=DER;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; loop;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;loop&lt;/I&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 08:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452738#M114282</guid>
      <dc:creator>hariscoric</dc:creator>
      <dc:date>2018-04-10T08:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple Excel sheets and merging them into one with a macro - SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452742#M114286</link>
      <description>&lt;P&gt;This a consequence of using a file format that is totally unsuited for a reliable data transfer between applications. With the Excel format, you have to rely on guessing mechanisms that SAS had to build into proc import and the libname definitions for Excel.&lt;/P&gt;
&lt;P&gt;Depending on content, your resulting data structures can (and will) look different with every run, causing the problems you experience.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Save to csv from Excel, and write a data step for the csv where YOU have control over the structure, and the following steps will encounter no problems anymore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And stop using stupid dataset names (&lt;FONT color="#3366ff"&gt;'20180301.'n&lt;/FONT&gt;). They only make work harder for no reason. Use a prefix that makes it a valid SAS name, so you don't have to type the 'some_****_in_here'n construct all the time.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 08:41:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452742#M114286</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-10T08:41:42Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple Excel sheets and merging them into one with a macro - SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452744#M114288</link>
      <description>&lt;P&gt;Well, your choice of data medium - Excel is not the best to start with.&amp;nbsp; You will get all sorts of issues as Excel is not a fixed format file, so merging etc. will be an issue.&amp;nbsp; Bear this in mid as each time you run the program you will likely end up with different looking data or outcomes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now to import data from XLSX, it has been made a lot easier with 9.4 and the libname excel.&amp;nbsp; For example to read all the sheets of xyz.xlsx into SAS then you can simply do:&lt;/P&gt;
&lt;PRE&gt;libname tmp xlsx "xyz.xlsx";

proc copy in=tmp out=work;
run;

libname tmp clear;&lt;/PRE&gt;
&lt;P&gt;This will create a dataset for all valid sheets in the Excel file, and copy them into your work library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will caution you again, this is not your problem, your problem is in the use of Excel as you will see each time you run this.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 08:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452744#M114288</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-04-10T08:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple Excel sheets and merging them into one with a macro - SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452887#M114344</link>
      <description>&lt;P&gt;You might discuss with whoever is creating these files if another file creation option such as CSV (or other delimited text file format) would be practical. The process might be creating Excel files because "every one wants Excel" is a default thought pattern for some. Even if some users of this data want the spreadsheet format it may well be possible to have interchange data provided in another form for you, especially if these files are created by another program (especially a data base). An agreed upon file format for each of these files, a data step to read each and the daily requirement becomes changing input file names and output data set names (if needed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another option to consider if this data is being created by a different data base is that SAS provides a number of ways to connect directly to many databases. Perhaps you might be better off with a SAS/ACCESS and direct connections to the data source. If the data comes from a database it is almost certain that data has consistent data properties.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Document how much time it takes to adjust everything for ONE day of data. Extrapolate that work load over a 4 or 6 month period. Talk to your supervisor about the total cost in man hours and resources the current data process involving Excel will entail as well as delays in response to questions based on this daily data from having to "fix" things daily. You might be surprised at the amount of management support might appear when $$$$ are pointed out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For what it may be worth: changing the informat property for a variable after it has been imported is basically lying to yourself and others. I really wouldn't want to explain why a variable has an informat of $60. when the actual length is 6&amp;nbsp;&amp;nbsp;or 120 characters.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 16:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/452887#M114344</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-10T16:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: Importing multiple Excel sheets and merging them into one with a macro - SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/453116#M114453</link>
      <description>&lt;P&gt;I've decided to exclude all empty Excel workbooks from the proc import. Afterwards I've added a proc sql - create table step where I format the variables. After the proc import I add:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* excludes all empty Excel workbooks from above proc import */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; dsid=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(open(DER.&amp;amp;&amp;amp;Name&amp;amp;i));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; numobs=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(attrn(&amp;amp;dsid,nobs)); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; rc=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(close(&amp;amp;dsid));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;numobs.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; eq &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%goto&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; exit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table DER&amp;amp;i&amp;nbsp; as select and format my variables&lt;/P&gt;&lt;P&gt;from &lt;FONT face="Courier New" size="2"&gt;DER.&amp;amp;&amp;amp;Name&amp;amp;i&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;/* Inserts all datasets from above into the first dataset from the Library */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; &amp;amp;i gt &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;insert into &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DER&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;1 select * from &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;DER&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;i;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%exit:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 09:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-multiple-Excel-sheets-and-merging-them-into-one-with-a/m-p/453116#M114453</guid>
      <dc:creator>hariscoric</dc:creator>
      <dc:date>2018-04-11T09:11:19Z</dc:date>
    </item>
  </channel>
</rss>

