<?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 multiple Excel files(xlsx) directly from zip file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444321#M111219</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check if this is helpful&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-sas/" target="_self"&gt;Using FILENAME ZIP to unzip and read data files in SAS&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 10 Mar 2018 00:46:26 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-03-10T00:46:26Z</dc:date>
    <item>
      <title>Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444296#M111205</link>
      <description>&lt;P&gt;I have lots of xlsx files in a zip file.&amp;nbsp; I would like to read it directly.&amp;nbsp; SAS cannot find xlsx file names.&amp;nbsp; Should the excel file names be same as the zip file name? Is it possible to read xlsx files in zip file directly?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename zipfile zip "e:\Users\mhollifi\Documents\Dillon Study GP\18_3_9\submission_cleaned.zip";
data test;
  infile zipfile(ajellowilliam_29616_1296089_MBTN_Peer_evalsGroup6.xlsx) recfm=f lrecl=1;
  file 'e:\Users\mhollifi\Documents\Dillon Study GP\18_3_9\ajellowilliam_29616_1296089_MBTN_Peer_evalsGroup6' recfm=f lrecl=1;
  input ch $char1.;
  put ch $char1.;
run;

ERROR: Entry ajellowilliam_29616_1296089_MBTN_Peer_evalsGroup6.xlsx in zip file
       e:\Users\mhollifi\Documents\Dillon Study GP\18_3_9\submission_cleaned.zip does not exist.
ERROR: Physical file does not exist, ajellowilliam_29616_1296089_MBTN_Peer_evalsGroup6.xlsx.
WARNING: The data set WORK.TEST may be incomplete.  When this step was stopped there were 0
         observations and 1 variables.
WARNING: Data set WORK.TEST was not replaced because this step was stopped.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 22:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444296#M111205</guid>
      <dc:creator>mhollifi</dc:creator>
      <dc:date>2018-03-09T22:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444297#M111206</link>
      <description>&lt;P&gt;I don't think it's possible to read a zipped xlsx file.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you usually don't get massive gains by zipping xlsx files because they're already compressed. If you change the extension of an xlsx&amp;nbsp;file to zip and uncompress it you can see the xml components.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 22:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444297#M111206</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-09T22:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444301#M111207</link>
      <description>&lt;P&gt;You cannot read from an XLSX file as if it was a simple text file.&lt;/P&gt;
&lt;P&gt;Are you trying to get the filenames?&lt;/P&gt;
&lt;P&gt;Try something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename zipfile zip "e:\Users\mhollifi\Documents\Dillon Study GP\18_3_9\submission_cleaned.zip";
data files ;
 length fileno 8 filename $256 ;
 did=dopen('zipfile');
 do fileno=1 to dnum(did);
   filename=dread(did,fileno);
   output;
 end;
 did=dclose(did);
 drop did;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 23:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444301#M111207</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-09T23:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444310#M111212</link>
      <description>&lt;P&gt;Thank you for your reply.&amp;nbsp; I tried to use your code, and I got this error message. Why?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename zipfile zip "e:\Users\mhollifi\Documents\Dillon Study GP\18_3_9\submission_cleaned.zip";
data _null_ ;
 length fileno 8 filename $256 ;
 did=dopen('zipfile');
 %do fileno=1 %to dnum(did);

ERROR: The %DO statement is not valid in open code.


   filename=dread(did,fileno);
   output;
    %readdata(filename)

MPRINT(READDATA):   filename zipfile clear;
MPRINT(READDATA):   proc import datafile="filename" out=want DBMS=EXCEL REPLACE;
MPRINT(READDATA):   AEXC;
MPRINT(READDATA):   RANGE="Sheet1$";
MPRINT(READDATA):   GETNAMES=YES;
MPRINT(READDATA):   MIXED=no;
MPRINT(READDATA):   SCANTEXT=YES;
MPRINT(READDATA):   USEDATE=YES;
MPRINT(READDATA):   SCANTIME=YES;
MPRINT(READDATA):   RUN;
ERROR: Unable to open file C:\Users\00004263\filename.XLS. It does not  exist or it is already
       opened exclusively by another user, or you need permission to view its data.
ERROR: The %END statement is not valid in open code.


 %end;
 did=dclose(did);
 drop did;

run;
%macro readdata(xlsfile);
filename zipfile clear;

proc import datafile="&amp;amp;xlsfile" out=want
     DBMS=EXCEL REPLACE;
     RANGE="Sheet1$"; 
     GETNAMES=YES;
     MIXED=no;
     SCANTEXT=YES;
     USEDATE=YES;
     SCANTIME=YES;
RUN;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Mar 2018 23:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444310#M111212</guid>
      <dc:creator>mhollifi</dc:creator>
      <dc:date>2018-03-09T23:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444317#M111216</link>
      <description>Why would you use a %DO loop in the middle of a data step?&lt;BR /&gt;</description>
      <pubDate>Sat, 10 Mar 2018 00:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444317#M111216</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-10T00:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444319#M111218</link>
      <description>&lt;P&gt;You will need to copy the files out of the ZIP file before you can use them with XLSX libname engine (or PROC IMPORT).&lt;/P&gt;
&lt;P&gt;Let's make a macro to copy one file and import all of the sheets into a SAS libref.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro import_xlsx(zipfile=,member=,outlib= );
%local filen dlm ;
%if "&amp;amp;sysscp" = "WIN" %then %let dlm=\ ;
%else %let dlm=/ ;
%let filen=%sysfunc(quote(%qsysfunc(pathname(work))&amp;amp;dlm.copy.xlsx));
filename file1 zip &amp;amp;zipfile member=&amp;amp;member recfm=n;
filename file2 &amp;amp;filen recfm=n;
data _null_;
  infile file1 recfm=n ;
  file file2 recfm=n ;
  input;
  put _infile_;
run;
libname xlsx xlsx &amp;amp;filen ;

proc copy inlib=xlsx outlib=&amp;amp;outlib;
run;

libname xlsx clear ;
data _null_;
  fileref='file2';
  rc=fdelete(fileref);
run;
filename file2 ;
filename file1 ;

%mend import_xlsx;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So now if you take the list of files you generated using the earlier data step you can use it to generate a series of calls to this macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code ;
data _null_;
  set files ;
  file code ;
  put '%import_xlsx(zipfile="zipfilename_goes_here"'
      ',member=' filename :$quote.
      ',outlib=work)'
  ;
run;
%include code / source2 ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Mar 2018 00:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444319#M111218</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-10T00:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444321#M111219</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check if this is helpful&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-sas/" target="_self"&gt;Using FILENAME ZIP to unzip and read data files in SAS&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 00:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444321#M111219</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-10T00:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444431#M111269</link>
      <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;&lt;P&gt;But hum...&lt;/P&gt;&lt;P&gt;Not quite sure what's going on to me.&lt;/P&gt;&lt;P&gt;I got this error message and I cannot figure out where "filename" variable comes from.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%local filen dlm ;
%if "&amp;amp;sysscp" = "WIN" %then %let dlm=\ ;
%else %let dlm=/ ;
%let filen=%sysfunc(quote(%qsysfunc(pathname(work))&amp;amp;dlm.copy.xlsx));
filename file1 zip &amp;amp;zipfile member=&amp;amp;member recfm=n;
filename file2 &amp;amp;filen recfm=n;
data _null_;
  infile file1 recfm=n ;
  file file2 recfm=n ;
  input;
  put _infile_;
run;
libname xlsx xlsx &amp;amp;filen ;

proc copy inlib=xlsx outlib=&amp;amp;outlib;
run;

libname xlsx clear ;
data _null_;
  fileref='file2';
  rc=fdelete(fileref);
run;
filename file2 ;
filename file1 ;

%mend import_xlsx;
*So now if you take the list of files you generated using the earlier data step you can use it to generate a series of calls to this macro.
filename code ;
data _null_;
  set files ;
  file code ;
  put '%import_xlsx(zipfile="e:\Users\mhollifi\Documents\Dillon Study GP\18_3_9\submission_cleaned.zip"'
      ',member=' filename :$quote.
      ',outlib=work)'
  ;
run;
%include code / source2 ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and error message is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Physical file does not exist, C:\Users\00004263\code.sas.
ERROR: Cannot open %INCLUDE file CODE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;in the end of line.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 19:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444431#M111269</guid>
      <dc:creator>mhollifi</dc:creator>
      <dc:date>2018-03-10T19:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444506#M111304</link>
      <description>&lt;P&gt;If you didn't create a dataset with the list of the files in the ZIP file then your data step to generate one macro call per filename will not generate ANY lines into the CODE file.&amp;nbsp; So of course there are no lines to %INCLUDE from the file.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Make sure to FIRST run the code I posted before for reading the names of the files that are in your ZIP file. And make sure not to mistakenly convert the data step DO loops into macro code %DO loops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also make sure that the name of the variable you created to hold the filename matches the name of the variable you are using to write the macro call into the text file CODE.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 03:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/444506#M111304</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-03-11T03:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/716708#M221543</link>
      <description>&lt;P&gt;Also you should replace this data step&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;filename file1 zip &amp;amp;zipfile member=&amp;amp;member recfm=n;
filename file2 &amp;amp;filen recfm=n;
data _null_;
  infile file1 recfm=n ;
  file file2 recfm=n ;
  input;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and use function fcopy instead.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 01:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/716708#M221543</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-04T01:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/716710#M221544</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/183698"&gt;@mhollifi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;I got this error message and I cannot figure out where "filename" variable comes from.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*So now if you take the list of files you generated using the earlier data step you can use it to generate a series of calls to this macro.
filename code ;
data _null_;
  set files ;
  file code ;
  put '%import_xlsx(zipfile="e:\Users\mhollifi\Documents\Dillon Study GP\18_3_9\submission_cleaned.zip"'
      ',member=' filename :$quote.
      ',outlib=work)'
  ;
run;
%include code / source2 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and error message is&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WARNING: Physical file does not exist, C:\Users\00004263\code.sas.
ERROR: Cannot open %INCLUDE file CODE.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the end of line.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you commented out the FILENAME statement the fileref of CODE was never defined. When you are writing to a file with the FILE statement in a datastep SAS will use a default extension of .dat.&amp;nbsp; But when you are using %INCLUDE to include a file of SAS code then SAS will use a default extension of .sas, so the %INCLUDE is not finding the file that the data step wrote.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So either add a semi-colon to the end of your comment so that the FILENAME statement will execute.&lt;/P&gt;
&lt;P&gt;Or use a quoted physical filename in the FILE and %INCLUDE statements instead of a fileref.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS Yet another reason why code lines should be limited to 75 characters.&amp;nbsp; You are more likely to notice lines that are missing the ending semi-colon.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 01:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/716710#M221544</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-04T01:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Import multiple Excel files(xlsx) directly from zip file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/716711#M221545</link>
      <description>&lt;P&gt;Sorry&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;I awoke this old thread. My mistake&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2021 01:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-multiple-Excel-files-xlsx-directly-from-zip-file/m-p/716711#M221545</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-04T01:35:03Z</dc:date>
    </item>
  </channel>
</rss>

