Hello,
I am creating a CSV file using a big SAS dataset. I need to zip the CSV file in multiple smaller zip file.
Can it be done using filename statement?
I need something similar to
zip -s 1000m SPLIT_FILES small_FILE.ZIP
Thanks.
The FILENAME statement will not do this.
You can either run a system command to split the zip file afterward, something like
zip existing.zip --out new.zip -s 50m
or create several independent files with FILENAME.
Hi,
Maybe something like this will help:
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 *&=directory.*;
/*options mprint;*/
%macro split2zips(data,variables,directory,parts=5);
data _null_;
call symputX("size",ceil(nobs/&parts.),"L");
stop;
set &data. nobs=nobs;
run;
%local I;
%do I = 1 %to &parts.;
FILENAME F ZIP "&directory./file_no&I..zip" MEMBER = "file_no&I..csv" Lrecl = 1024;
data _null_;
FILE F;
SET &data.(
keep = &variables.
firstobs = %sysevalf((&I.-1)*&size. + 1)
obs = %sysevalf(&I.*&size.)
);
PUT "&I." (_ALL_) (","); /*adjust to your needs*/
run;
FILENAME F;
%end;
%mend split2zips;
%split2zips(have, i x, &directory.)
All the best
Bart
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.