<?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 .xls files in to sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413273#M279938</link>
    <description>&lt;P&gt;Hi Draycut,&lt;/P&gt;
&lt;P&gt;I did use the code and the result was that a data set has been created with all the file names in the given location which is great but, I am trying to update a column names cntry cde in each file with its file name and import all those xls files intoto sas atonce... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2017 11:22:50 GMT</pubDate>
    <dc:creator>don21</dc:creator>
    <dc:date>2017-11-14T11:22:50Z</dc:date>
    <item>
      <title>importing multiple .xls files in to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413250#M279934</link>
      <description>&lt;P&gt;dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a requirement to impot some 42 .xls files into sas &amp;nbsp;atonce.&lt;/P&gt;
&lt;P&gt;1. All the files are from same location (let say they are country files).&lt;/P&gt;
&lt;P&gt;2. all are .xls files&lt;/P&gt;
&lt;P&gt;3. all of them have same variable names (46 variables in each)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Challenges:&lt;/P&gt;
&lt;P&gt;1. they doesnt have a variable in them saying "country" (because the file name itself gives the country name)&lt;/P&gt;
&lt;P&gt;2. the sample import query did not work when tried to import a single file (Error: "Too many XF records for Excel" and "Requested Input File Is Invalid")&lt;/P&gt;
&lt;P&gt;3. if we succeed to import them all at once, there is a problem in identifying the data (like which belongs to which country)&lt;/P&gt;
&lt;P&gt;4. there should be column created in the data with country name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any way to create a column "country in each of the file and import them atonce???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 10:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413250#M279934</guid>
      <dc:creator>don21</dc:creator>
      <dc:date>2017-11-14T10:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: importing multiple .xls files in to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413253#M279935</link>
      <description>&lt;P&gt;You can use this example to import all files from a directory&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/41/880.html" target="_blank"&gt;http://support.sas.com/kb/41/880.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, I would use the &lt;A href="http://documentation.sas.com/?docsetId=sclref&amp;amp;docsetTarget=p1b8y2nwueeregn1c416y4l149px.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;DSNAME Function&lt;/A&gt;&amp;nbsp;to assign the data set name to a new variable in each of your data sets.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 10:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413253#M279935</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-11-14T10:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: importing multiple .xls files in to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413255#M279936</link>
      <description>&lt;P&gt;Can the crappy Excel format, use .csv files. A multiple of CSV files can easily be imported in a single data step using wildcards, and the name of the currently read file can be determined within the step. See the documentation of the infile statement.&lt;/P&gt;
&lt;P&gt;With proc import, you have to import each file separately, and then combine the resulting datasets, using a similar technique in the set statement. But be aware that datasets imported with the &lt;EM&gt;guessing&lt;/EM&gt; procedure proc import can (and will) have different attributes, causing WARNINGs or ERRORs and possible data loss when concatenating.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 10:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413255#M279936</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-14T10:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: importing multiple .xls files in to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413264#M279937</link>
      <description>&lt;P&gt;Ah, I believe this goes back to the thread last week.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Importing-multiple-pwd-protected-xlfiles-from-a-URL-at-the-same/m-p/412243#M26483" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/Importing-multiple-pwd-protected-xlfiles-from-a-URL-at-the-same/m-p/412243#M26483&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can import all the files in a folder, either by command line or by using dopen() type functions and looping over that:&lt;/P&gt;
&lt;PRE&gt;filename tmp pipe 'dir "c:\tmp\*.xls" /b";

data _null_;
  infile tmp;
  input;
  call execute('proc import datafile="'||strip(_input_)||'" out=want'||strip(put(_n_,best.)||'; run;');
run;&lt;/PRE&gt;
&lt;P&gt;This creates a proc import for each file returned by the dos command dir.&amp;nbsp; You can do the same using dopen:&lt;/P&gt;
&lt;PRE&gt;data _null_;
   drop rc did;
   rc=filename("mydir","physical-name");
   did=dopen("mydir");
   if did &amp;gt; 0 then do;
     do i=1 to did;
       call execute('proc import....');
     end;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;However there is no way of telling up front if:&lt;/P&gt;
&lt;P&gt;a) the proc import will work&lt;/P&gt;
&lt;P&gt;b) it will give the same result&lt;/P&gt;
&lt;P&gt;Excel is a really bad format, proc import is a guessing procedure, put the two together and you have a mess.&amp;nbsp; The safest way is to create a migration plan, convert the data into usable format, then read the usable format based on a given specification - then the process is repeatable and auditable.&amp;nbsp; Also if the files change in the future you have evidence to go back and bill them again to re-work.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 10:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413264#M279937</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-14T10:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: importing multiple .xls files in to sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413273#M279938</link>
      <description>&lt;P&gt;Hi Draycut,&lt;/P&gt;
&lt;P&gt;I did use the code and the result was that a data set has been created with all the file names in the given location which is great but, I am trying to update a column names cntry cde in each file with its file name and import all those xls files intoto sas atonce... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 11:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/importing-multiple-xls-files-in-to-sas/m-p/413273#M279938</guid>
      <dc:creator>don21</dc:creator>
      <dc:date>2017-11-14T11:22:50Z</dc:date>
    </item>
  </channel>
</rss>

