BookmarkSubscribeRSS Feed
phadnismukta
Fluorite | Level 6

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.

 

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

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. 

yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 965 views
  • 2 likes
  • 3 in conversation