<?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: Creating a csv file and zipping it with multiple smaller  files in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-csv-file-and-zipping-it-with-multiple-smaller-files/m-p/647003#M193593</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe something like this will help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do i = 1 to 100;
  x = "ABC";
  output;
end;
run;


%let directory = %sysfunc(pathname(work)); /* put the directory you want to store files here */
%put *&amp;amp;=directory.*;

/*options mprint;*/
%macro split2zips(data,variables,directory,parts=5);
data _null_;
  call symputX("size",ceil(nobs/&amp;amp;parts.),"L"); 
  stop;
  set &amp;amp;data. nobs=nobs;
run;

%local I;
%do I = 1 %to &amp;amp;parts.;

FILENAME F ZIP "&amp;amp;directory./file_no&amp;amp;I..zip" MEMBER = "file_no&amp;amp;I..csv" Lrecl = 1024; 
data _null_;
  FILE F;
  SET &amp;amp;data.(
      keep = &amp;amp;variables. 
      firstobs = %sysevalf((&amp;amp;I.-1)*&amp;amp;size. + 1) 
      obs      = %sysevalf(&amp;amp;I.*&amp;amp;size.)
      );
  PUT "&amp;amp;I." (_ALL_) (","); /*adjust to your needs*/
run; 
FILENAME F;
%end;


%mend split2zips;

%split2zips(have, i x, &amp;amp;directory.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Tue, 12 May 2020 09:00:12 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-05-12T09:00:12Z</dc:date>
    <item>
      <title>Creating a csv file and zipping it with multiple smaller  files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-csv-file-and-zipping-it-with-multiple-smaller-files/m-p/646981#M193585</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am creating a CSV file using a big SAS dataset. I need to zip the CSV file in multiple smaller zip file.&lt;/P&gt;&lt;P&gt;Can it be done using filename statement?&lt;/P&gt;&lt;P&gt;I need something similar to&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;SPAN class="pln"&gt;zip &lt;/SPAN&gt;&lt;SPAN class="pun"&gt;-&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;s &lt;/SPAN&gt;&lt;SPAN class="lit"&gt;1000m&lt;/SPAN&gt;&lt;/U&gt;&lt;SPAN class="pln"&gt; SPLIT_FILES small_FILE&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;.&lt;/SPAN&gt;&lt;SPAN class="pln"&gt;ZIP&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="pln"&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 07:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-csv-file-and-zipping-it-with-multiple-smaller-files/m-p/646981#M193585</guid>
      <dc:creator>phadnismukta</dc:creator>
      <dc:date>2020-05-12T07:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a csv file and zipping it with multiple smaller  files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-csv-file-and-zipping-it-with-multiple-smaller-files/m-p/647001#M193591</link>
      <description>&lt;P&gt;The FILENAME statement will not do this.&lt;/P&gt;
&lt;P&gt;You can either run a system command to split the zip file afterward, something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;zip existing.zip --out new.zip -s 50m&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or create several independent files with FILENAME.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 08:55:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-csv-file-and-zipping-it-with-multiple-smaller-files/m-p/647001#M193591</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-12T08:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a csv file and zipping it with multiple smaller  files</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-csv-file-and-zipping-it-with-multiple-smaller-files/m-p/647003#M193593</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe something like this will help:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do i = 1 to 100;
  x = "ABC";
  output;
end;
run;


%let directory = %sysfunc(pathname(work)); /* put the directory you want to store files here */
%put *&amp;amp;=directory.*;

/*options mprint;*/
%macro split2zips(data,variables,directory,parts=5);
data _null_;
  call symputX("size",ceil(nobs/&amp;amp;parts.),"L"); 
  stop;
  set &amp;amp;data. nobs=nobs;
run;

%local I;
%do I = 1 %to &amp;amp;parts.;

FILENAME F ZIP "&amp;amp;directory./file_no&amp;amp;I..zip" MEMBER = "file_no&amp;amp;I..csv" Lrecl = 1024; 
data _null_;
  FILE F;
  SET &amp;amp;data.(
      keep = &amp;amp;variables. 
      firstobs = %sysevalf((&amp;amp;I.-1)*&amp;amp;size. + 1) 
      obs      = %sysevalf(&amp;amp;I.*&amp;amp;size.)
      );
  PUT "&amp;amp;I." (_ALL_) (","); /*adjust to your needs*/
run; 
FILENAME F;
%end;


%mend split2zips;

%split2zips(have, i x, &amp;amp;directory.)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 09:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-csv-file-and-zipping-it-with-multiple-smaller-files/m-p/647003#M193593</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-05-12T09:00:12Z</dc:date>
    </item>
  </channel>
</rss>

