<?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 Create the Zip folder with existing Folder using SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970880#M377199</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to do the following&lt;/P&gt;&lt;P&gt;1. 'Folder1' Contains all the different files.&lt;/P&gt;&lt;P&gt;2. I want to copy the specific CSV file into 'Folder2';&lt;/P&gt;&lt;P&gt;3. Finally I want to Zip the 'Folder 2' and Create the 'Folder2.Zip'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp; am stuck at step 3, I see the&amp;nbsp; 'ODS PACKAGES' (&lt;A href="https://blogs.sas.com/content/sasdummy/2014/01/28/create-zip-ods-package/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sasdummy/2014/01/28/create-zip-ods-package/&lt;/A&gt;) unfortunately, I am not able to succeed. I am using SAS9.4 Windows environment.&lt;/P&gt;&lt;P&gt;Any inputs greatly appreciated.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let pathscr = %str(C:\folder1);
%let pathdes = %str(C:\folder2);
data _null_;
  length fref $8 fname $256 cmd $500;
  did = filename(fref,"&amp;amp;pathscr");
  did = dopen(fref);
  
  if did = 0 then do;
    put "ERROR: Could not open directory &amp;amp;pathscr";
    stop;
  end;
  
  do i = 1 to dnum(did);
    fname = dread(did,i);
    if find(FNAME,'.CSV') then do;
      /* Use Windows copy command with /B and /Y options to preserve timestamps */
      cmd = 'cmd.exe /c copy /B /Y "' || 
            catx('\', "&amp;amp;pathscr", fname) || 
            '" "' || 
            catx('\', "&amp;amp;pathdes", fname) || 
            '"';
      rc = system(cmd);
      
      if rc = 0 then
        put "Successfully copied: " fname;
      else
        put "ERROR copying: " fname " Return code: " rc;
    end;
  end;
  
  did = dclose(did);
  rc = filename(fref);

run&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jul 2025 17:40:57 GMT</pubDate>
    <dc:creator>xiong</dc:creator>
    <dc:date>2025-07-16T17:40:57Z</dc:date>
    <item>
      <title>Create the Zip folder with existing Folder using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970880#M377199</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to do the following&lt;/P&gt;&lt;P&gt;1. 'Folder1' Contains all the different files.&lt;/P&gt;&lt;P&gt;2. I want to copy the specific CSV file into 'Folder2';&lt;/P&gt;&lt;P&gt;3. Finally I want to Zip the 'Folder 2' and Create the 'Folder2.Zip'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp; am stuck at step 3, I see the&amp;nbsp; 'ODS PACKAGES' (&lt;A href="https://blogs.sas.com/content/sasdummy/2014/01/28/create-zip-ods-package/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sasdummy/2014/01/28/create-zip-ods-package/&lt;/A&gt;) unfortunately, I am not able to succeed. I am using SAS9.4 Windows environment.&lt;/P&gt;&lt;P&gt;Any inputs greatly appreciated.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let pathscr = %str(C:\folder1);
%let pathdes = %str(C:\folder2);
data _null_;
  length fref $8 fname $256 cmd $500;
  did = filename(fref,"&amp;amp;pathscr");
  did = dopen(fref);
  
  if did = 0 then do;
    put "ERROR: Could not open directory &amp;amp;pathscr";
    stop;
  end;
  
  do i = 1 to dnum(did);
    fname = dread(did,i);
    if find(FNAME,'.CSV') then do;
      /* Use Windows copy command with /B and /Y options to preserve timestamps */
      cmd = 'cmd.exe /c copy /B /Y "' || 
            catx('\', "&amp;amp;pathscr", fname) || 
            '" "' || 
            catx('\', "&amp;amp;pathdes", fname) || 
            '"';
      rc = system(cmd);
      
      if rc = 0 then
        put "Successfully copied: " fname;
      else
        put "ERROR copying: " fname " Return code: " rc;
    end;
  end;
  
  did = dclose(did);
  rc = filename(fref);

run&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jul 2025 17:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970880#M377199</guid>
      <dc:creator>xiong</dc:creator>
      <dc:date>2025-07-16T17:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create the Zip folder with existing Folder using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970882#M377201</link>
      <description>&lt;P&gt;Do you really need to make two copies of the files? One in the directory and the second copy in the ZIP file.&amp;nbsp; Or is it sufficient to just put the files into the ZIP file directly?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you seem to want to copy TEXT files you can probably just use a data step to do the whole thing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sdir = c:\downloads ;
%let zipfile = c:\downloads\csv_copy.zip ;

data _null_;
  length fname memname $200;
  infile "&amp;amp;sdir\*.csv" filename=fname ;
  input;
  memname = scan(fname,-1,'/\');
  file "&amp;amp;zipfile" zip memvar=memname;
  put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jul 2025 18:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970882#M377201</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-16T18:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create the Zip folder with existing Folder using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970887#M377204</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your Response, I am OK either way.&amp;nbsp; I just created two copies, since I am not sure How to move the required files from 'Folder1' to 'Folder2. Zip' directly also I want to control the zip folder name ( keep it as copy). One question to your code. Does it remains the metadata attributes of the original file when copied ( like time stamps).&amp;nbsp; I will give it a try using your code.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jul 2025 18:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970887#M377204</guid>
      <dc:creator>xiong</dc:creator>
      <dc:date>2025-07-16T18:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create the Zip folder with existing Folder using SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970888#M377205</link>
      <description>&lt;P&gt;It will make new files, so the timestamp on the files should be when you ran the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to retain the timestamp you could try using the list of filenames to generate the code to copy the files.&amp;nbsp; For such jobs I find it works much easier to use a data step to write the desired code to a file and then use %INCLUDE to run the generated code.&amp;nbsp; Then you can use the full power of the data step (and especially the PUT statement) to generate the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sdir=C:\downloads ;
%let zipfile=c:\csv_copy.zip;

filename code temp;
data _null_;
  file code;
  infile "dir /b &amp;amp;sdir\*.csv" pipe truncover;
  input member $200. ;
  length fname $300 ;
  fname=quote(catx('\',"&amp;amp;sdir",member),"'");
  put 'filename in ' fname ';' ;
  put "filename out zip '&amp;amp;zipfile' " member= :$quote. ';' ;
  put '%let rc=%sysfunc(fcopy(in,out));' ;
run;

%include code / source2 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note if you cannot use the PIPE method then use some other method to find the list of CSV files.&amp;nbsp; Such as this macro:&amp;nbsp;&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/dirtree.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/dirtree.sas&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jul 2025 19:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-the-Zip-folder-with-existing-Folder-using-SAS/m-p/970888#M377205</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-07-16T19:16:45Z</dc:date>
    </item>
  </channel>
</rss>

