<?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: Zip/Unzip Macro using VBScript won't overwrite files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503545#M134572</link>
    <description>Are you stuck with this process? What types of files are in the zip file? Text? Sas data sets? What version of SAS do you have?&lt;BR /&gt;&lt;BR /&gt;The reason I ask, is that newer versions of SAS has automated ways of doing this without the need for VBS. If you have the latest version you can read a text file directly from the ZIP file without having to uncompress it.</description>
    <pubDate>Thu, 11 Oct 2018 20:08:19 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-10-11T20:08:19Z</dc:date>
    <item>
      <title>Zip/Unzip Macro using VBScript won't overwrite files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503512#M134553</link>
      <description>&lt;P&gt;I found &lt;A href="http://support.sas.com/resources/papers/proceedings12/057-2012.pdf" target="_self"&gt;a macro presented at SAS Global Forum&lt;/A&gt; to help zip/unzip compressed files. I am downloading a zip file daily, extracting the files to a folder, then performing further processing in SAS. The zip file contains the same set of files every time - I need to unzip the files and then overwrite the previous day's files. I'm trying to run my program in batch mode, and keep getting the window that asks me to confirm whether or not I want to replace the files. I need to suppress this window and have the files overwrite automatically. I don't know enough about VBScript to understand where to insert an overwrite option. What modification do I need to make?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro SASZip_Lite(zip=, sfdr=, fstyl=%str(*.sas*dat), tfdr=);
  /****************************************************************
  The code posted below is provided "AS IS" with NO WARRANTIES.
  ZIP: directory and file name of zip archive
  SFDR: directory of source files (to be zipped)
  FSTYL: File type of source files; value: *.* as "zip a folder"
  TFDR: Target directory for unzipped files (for unzip)
  *****************************************************************/ 

%local zip sfdr fstyl tfdr vbadir p q mode;

 /* Set up a temporary working folder for VBScript */
    %let vbsdir=c:\MyZi$Dir;

 options noxwait;

 /* To initiate a clean working space */
 %if %sysfunc(fileexist("&amp;amp;vbsdir"))=1 %then %sysexec rd /s/q "&amp;amp;vbsdir";
 %if %index(%upcase(&amp;amp;zip), .ZIP)=0 %then %let zip=&amp;amp;zip..zip;
 %let mode=;

 /* Compress (zip) files */
 %if %length(&amp;amp;sfdr)&amp;gt;0 and (%length(&amp;amp;zip)&amp;gt;0) %then %do;
 	/* Extract directory name of the zip file, if no such folder, generate one */
 	%let q=%sysfunc(tranwrd(&amp;amp;zip, %scan(&amp;amp;zip, -1, %str(\)), %str( )));
 	%let q=%substr(&amp;amp;q, 1, %length(&amp;amp;q)-1);
 	%if %sysfunc(fileexist("&amp;amp;q"))=0 %then %sysexec md "&amp;amp;q";

 	/* Copy all requested files from a validated source folder to a temporary folder,
 		and keep their original time stamps */
 	%if %length(&amp;amp;sfdr)&amp;gt;0 and %sysfunc(fileexist("&amp;amp;sfdr"))=1 %then %do;
 		%let mode=z;
 		%sysexec md "&amp;amp;vbsdir";
 		%if %qupcase(&amp;amp;fstyl)^=%str(*.*) %then %do;
 			%sysexec md "&amp;amp;vbsdir.\temp_zip";
 			%sysexec copy "&amp;amp;sfdr.\&amp;amp;fstyl" "&amp;amp;vbsdir.\temp_zip"; 
 		%end;
 	%end;
%end;
%else %if %length(&amp;amp;tfdr)&amp;gt;0 and %length(&amp;amp;zip)&amp;gt;0 and %sysfunc(fileexist("&amp;amp;zip"))&amp;gt;0
%then %do; /* Unzip files */
  %let mode=u;
  %sysexec md "&amp;amp;vbsdir";
%end; 

%if &amp;amp;mode=z or &amp;amp;mode=u %then %do;
 /* Generate VBScript based on different modes */
 	data _null_;
 		FILE "&amp;amp;vbsdir.\xpzip.vbs";
 		put 'Set ZipArgs = WScript.Arguments';
 		put 'InputFile = ZipArgs(0)';
 		put 'TgtFile = ZipArgs(1)';
 		put 'Set objShell = CreateObject("Shell.Application")';
 		put 'Set source = objShell.NameSpace(InputFile).Items';
 		put 'soucnt = objShell.NameSpace(InputFile).Items.Count';

 		%if &amp;amp;mode=z %then %do;
 			put 'CreateObject("Scripting.FileSystemObject").CreateTextFile(TgtFile,
		 		 True).Write "PK" &amp;amp; Chr(5) &amp;amp; Chr(6) &amp;amp; String(18, Chr(0))';
 			put 'objShell.NameSpace(TgtFile).CopyHere(source)';
 			put 'Do Until objShell.NameSpace(TgtFile).Items.Count = soucnt';
 			put 'wScript.Sleep 3000';
 			put 'Loop';
 		%end;
 		%else put 'objShell.NameSpace(TgtFile).CopyHere(source)'; ;
 		put 'wScript.Sleep 3000';
  	run;

	 /* Run VBScript file for data archiving */
 	%if &amp;amp;mode=z %then %do;

 		%if %qupcase(&amp;amp;fstyl)=%str(*.*) %then %sysexec CScript "&amp;amp;vbsdir.\xpzip.vbs"
			  "&amp;amp;sfdr" "&amp;amp;zip";
 			%else %sysexec CScript "&amp;amp;vbsdir.\xpzip.vbs" "&amp;amp;vbsdir.\temp_zip" "&amp;amp;zip";
 	%end;
 	%else %sysexec CScript "&amp;amp;vbsdir.\xpzip.vbs" "&amp;amp;zip" "&amp;amp;tfdr";
%end;

 /* Clean up */
 %if %sysfunc(fileexist("&amp;amp;vbsdir"))=1 %then %sysexec rd /s/q "&amp;amp;vbsdir";

%mend SASZip_Lite; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Oct 2018 18:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503512#M134553</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2018-10-11T18:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Zip/Unzip Macro using VBScript won't overwrite files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503545#M134572</link>
      <description>Are you stuck with this process? What types of files are in the zip file? Text? Sas data sets? What version of SAS do you have?&lt;BR /&gt;&lt;BR /&gt;The reason I ask, is that newer versions of SAS has automated ways of doing this without the need for VBS. If you have the latest version you can read a text file directly from the ZIP file without having to uncompress it.</description>
      <pubDate>Thu, 11 Oct 2018 20:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503545#M134572</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-11T20:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: Zip/Unzip Macro using VBScript won't overwrite files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503552#M134579</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;- definitely open to another way if there is one. ZIP contains CSV files. Running SAS 9.4 on Windows 10.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have another process later on that extracts the names from the CSV files using the filename statement - not sure if that is dependent upon the files being unzipped already, or not. This is the code that needs to follow the unzipping of the file:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csvfiles pipe "dir ""&amp;amp;directory\*.csv"" /b";

data csvlist;
	length csvname $100; 
    infile csvfiles length=reclen;
	input csvname $varying100. reclen;
run;

data _null_;
	set csvlist end=end;
	count+1;
	call symputx('path'||put(count,4.-l),cats("&amp;amp;directory\",csvname));
	call symputx('sasname'||put(count,4.-l),scan(csvname,1,'.'));
	if end then call symputx('max',count);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 20:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503552#M134579</guid>
      <dc:creator>viola</dc:creator>
      <dc:date>2018-10-11T20:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Zip/Unzip Macro using VBScript won't overwrite files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503557#M134582</link>
      <description>&lt;P&gt;This is probably what you want then:&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="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-sas/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the code is at the bottom of the blog post. For a text file, you can read it directly from the zip file, the documentation has an example, the third one.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsglobal&amp;amp;docsetTarget=n1dn0f61yfyzton1l2ngsa1clllr.htm&amp;amp;locale=en#p0ev6qrbgvl7p3n148timdyxob68" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lestmtsglobal&amp;amp;docsetTarget=n1dn0f61yfyzton1l2ngsa1clllr.htm&amp;amp;locale=en#p0ev6qrbgvl7p3n148timdyxob68&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/80715"&gt;@viola&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;- definitely open to another way if there is one. ZIP contains CSV files. Running SAS 9.4 on Windows 10.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have another process later on that extracts the names from the CSV files using the filename statement - not sure if that is dependent upon the files being unzipped already, or not. This is the code that needs to follow the unzipping of the file:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csvfiles pipe "dir ""&amp;amp;directory\*.csv"" /b";

data csvlist;
	length csvname $100; 
    infile csvfiles length=reclen;
	input csvname $varying100. reclen;
run;

data _null_;
	set csvlist end=end;
	count+1;
	call symputx('path'||put(count,4.-l),cats("&amp;amp;directory\",csvname));
	call symputx('sasname'||put(count,4.-l),scan(csvname,1,'.'));
	if end then call symputx('max',count);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Oct 2018 20:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Zip-Unzip-Macro-using-VBScript-won-t-overwrite-files/m-p/503557#M134582</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-11T20:39:40Z</dc:date>
    </item>
  </channel>
</rss>

