<?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: SAS to import multiple data where the file path&amp;amp;Name in Excel in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/690886#M24801</link>
    <description>&lt;P&gt;Your Excel file should contain two values: the name of the file to be imported, and the name of the resulting dataset. Very often, filenames can't be used as dataset names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Import the Excel file, and use a DATA _NULL_&amp;nbsp; step to build your import code for each entry with CALL EXECUTE. Or write the code to a temporary file, which you later %INCLUDE.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Oct 2020 06:02:24 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-10-12T06:02:24Z</dc:date>
    <item>
      <title>SAS to import multiple data where the file path&amp;Name in Excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/690883#M24800</link>
      <description>Hi All, I have a situation where I need to import multiple files, and the file path and file name is in excel. Example: I have to import 3 text files from 3 different locations (locations are keep changing). I have 1 excel file where it has information on file path in Column A and filename in Column B. How do I import all 3 files into the SAS program. Please help me. Thank you in advance.</description>
      <pubDate>Mon, 12 Oct 2020 05:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/690883#M24800</guid>
      <dc:creator>ChiefYuri</dc:creator>
      <dc:date>2020-10-12T05:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to import multiple data where the file path&amp;Name in Excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/690886#M24801</link>
      <description>&lt;P&gt;Your Excel file should contain two values: the name of the file to be imported, and the name of the resulting dataset. Very often, filenames can't be used as dataset names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Import the Excel file, and use a DATA _NULL_&amp;nbsp; step to build your import code for each entry with CALL EXECUTE. Or write the code to a temporary file, which you later %INCLUDE.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 06:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/690886#M24801</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-12T06:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to import multiple data where the file path&amp;Name in Excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/690994#M24810</link>
      <description>&lt;P&gt;I'd do this:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;import the Excel file&lt;/LI&gt;
&lt;LI&gt;In a DATA _NULL_ step:
&lt;OL&gt;
&lt;LI&gt;Use COMPRESS to convert the file name, which may include unacceptable characters, to a valid SAS table name.&lt;/LI&gt;
&lt;LI&gt;Construct PROC IMPORT step code to import the file&lt;/LI&gt;
&lt;LI&gt;Use CALL EXECUTE to execute the command.&lt;/LI&gt;
&lt;/OL&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Here is a template for the process. The first part just builds some sample files for testing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create the data used for testing */
%let path=c:\temp;
libname x xlsx "&amp;amp;path\files.xlsx";
data x.sheet1; 
   infile datalines dsd truncover;
   input a:$15. b:$21.;
datalines;
c:\temp,file1.csv
c:\temp,poorly named file.csv
;

libname x clear;
data _null_;
   file "c:\temp\file1.csv";
   put "ID,Name";
   put "1,Sam";
   put "2,Sally";

   file "c:\temp\poorly named file.csv";
   put "ID,Name";
   put "3,Ansel";
   put "4,Anne";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now that we have some files to play with, here is a template for doing the deed:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Import the file list data from the Excel file */
proc import datafile = "&amp;amp;path\files.xlsx" 
   dbms=xlsx
   out =work.fileList replace;
/* if your Excel file had no headler row */
/*   getnames=no*/
   ;
run;quit;

data _null_;
  set work.fileList;
  /*extract the file name without extension*/
  tableName=scan(b,1,'\/.');
  /*Remove any characters invlaid for SAS names from the file name*/
  tableName=compress(tableName,,'kn');
/*  construct the command to import the current file*/
  command=catx(' '
              ,cats('PROC IMPORT OUT= WORK.',tableName)
              ,cats('DATAFILE="',a,'\',b,'"') 
              ,'DBMS=CSV REPLACE; GETNAMES=YES;run; quit;'
              );
   put command=;
  /* Import the file */
  call execute(command); 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And - voilá!&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 15:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/690994#M24810</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2020-10-12T15:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to import multiple data where the file path&amp;Name in Excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691121#M24813</link>
      <description>&lt;P&gt;Thank you for reply. Im still new to this and i kind of hard to imagine on writing the code. Anyway, Thank you for your time &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 02:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691121#M24813</guid>
      <dc:creator>ChiefYuri</dc:creator>
      <dc:date>2020-10-13T02:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to import multiple data where the file path&amp;Name in Excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691122#M24814</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;I still trying to get the code ready as I stumbled to error codes below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: The XLSX engine cannot be found.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Error in the LIBNAME statement.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;I changed the XLSX to EXCEL and XLS also will show error (currently working on SAS Enterprise Guide 8.1). I will try to find way how to solve the issue and test the code again.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 02:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691122#M24814</guid>
      <dc:creator>ChiefYuri</dc:creator>
      <dc:date>2020-10-13T02:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to import multiple data where the file path&amp;Name in Excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691133#M24815</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I change the excel file to become CSV and some tweak here &amp;amp; there and it works now.&lt;/P&gt;&lt;P&gt;Thank you for the sample solution.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2020 03:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691133#M24815</guid>
      <dc:creator>ChiefYuri</dc:creator>
      <dc:date>2020-10-13T03:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: SAS to import multiple data where the file path&amp;Name in Excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691334#M24820</link>
      <description>My pleasure! Stay SASy, my friend &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 13 Oct 2020 16:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-to-import-multiple-data-where-the-file-path-amp-Name-in/m-p/691334#M24820</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2020-10-13T16:27:55Z</dc:date>
    </item>
  </channel>
</rss>

