BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
marymarion
Obsidian | Level 7
filename in '/home/u50158717/FILES(HOME)'; /* Specify the input directory */
filename out '/home/u50158717/FILES.HOME.zip'; /* Specify the output zip file */
data _null_;
    length fname mname $256;
    infile in('*') filename=fname truncover; /* Use the INFILE statement to read the contents of the input directory */
    input;
    mname = scan(fname,-1,'/\'); /* Extract the filename from the filepath */
    file out MEMVAR=mname; /* Use the FILE statement to specify the output file */
    put _infile_; /* Write the content of each file to the output file */
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Any time you have questions about the behavior or results of code provide the LOG from running the code.

We can't just copy your code and run it because we haven't your data or other files that may be in the folder, permissions to your location.

 

So the only way we have a chance of seeing what is happening is if you share the LOG.

View solution in original post

5 REPLIES 5
Reeza
Super User

See this helpful macro

Sample 45256: How to zip all data sets in a directory using ODS

 


@marymarion wrote:
filename in '/home/u50158717/FILES(HOME)'; /* Specify the input directory */
filename out '/home/u50158717/FILES.HOME.zip'; /* Specify the output zip file */
data _null_;
    length fname mname $256;
    infile in('*') filename=fname truncover; /* Use the INFILE statement to read the contents of the input directory */
    input;
    mname = scan(fname,-1,'/\'); /* Extract the filename from the filepath */
    file out MEMVAR=mname; /* Use the FILE statement to specify the output file */
    put _infile_; /* Write the content of each file to the output file */
run;

 

marymarion
Obsidian | Level 7
This still does not run.  I am on a -2 server (u50158717-2). Could that be it. How would instructions change?  Mary

filename in '/home/u50158717/FILE(HOME)'; filename out zip '/home/u50158717/FILE.HOME.zip'; data _null_; length fname mname $256 ; infile in('*') filename=fname ; input; mname = scan(fname,-1,'/\'); file out MEMVAR=mname; put _infile_; run; quit; filename in '/home/u50158717/vt'; filename out zip '/home/u50158717/vt.zip'; data _null_; length fname mname $256 ; infile in('*') filename=fname ; input; mname = scan(fname,-1,'/\'); file out MEMVAR=mname; put _infile_; run; quit; filename in '/home/u50158717/gpa'; filename out zip '/home/u50158717/gpa.zip'; data _null_; length fname mname $256 ; infile in('*') filename=fname ; input; mname = scan(fname,-1,'/\'); file out MEMVAR=mname; put _infile_; run; quit;
ballardw
Super User

Any time you have questions about the behavior or results of code provide the LOG from running the code.

We can't just copy your code and run it because we haven't your data or other files that may be in the folder, permissions to your location.

 

So the only way we have a chance of seeing what is happening is if you share the LOG.

Tom
Super User Tom
Super User

Does the ZIP engine actually allow you to write multiple files in one step like that?  Did you test it independently first?

 

Also do you really have a directory name that has parentheses in it like that?

yabwon
Onyx | Level 15

Use BasePlus package, it has the %zipArch() macro which does the job, and also the %unzipArch() which un-zips zip created by the first one (of course regular zipps like 7zip or unzip works too).

 

Example:


options dlCreateDir;
libname arch1 "%workPath()/testArch1";
libname arch2 "%workPath()/testArch2";

filename arch1 "%workPath()/testArch1";

data _null_;
  file arch1(test1.txt);
  put "text for test file 1";
data _null_;
  file arch1(test2.txt);
  put "text for test file 2";
data _null_;
  file arch1(test3.txt);
  put "text for test file 3";
run;

data arch1.class(index=(name));
  set sashelp.class;
run;
data arch1.cars(index=(model));
  set sashelp.cars;
run;



%zipArch(
  archName1.zip
, path = %workPath()/testArch1
, list = 1 
, overwrite = 1

)

%zipArch(
  archName2.zip
, pathRef = arch1
, target = %workPath()/testArch2
, list = 1 
, overwrite = 1
)


%unzipArch(
  archName2.zip 
, path = %workPath()/testArch2
, target = %workPath()/testArch2
, clean=1
, list=1
);

 

Bart

 

 

P.S. How to get BasePlus?

To work with SAS Packages like BasePlus or others you will need SAS Packages Framework.

 

Lets assume your SAS session has access to the internet (if not look below).

1) Create a directory where you want to store SPF and packages, for example let it be: "/home/myuserid/SASpackages" under Linux or "C:\Users\myuserid\SASpackages" under Windows.

2) Run the following code only one time to get the SPF:

filename packages "/home/myuserid/SASpackages"; /* setup directory for packages */
filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas";
%include SPFinit; /* enable the framework */

%installPackage(SPFinit) /* install SPF */
%installPackage(BasePlus) /* install BasePlus */

(installation of other packages goes the same way - by installPackage macro).

3) From now on, in this and any new SAS session, to enable SPF and BasePlus just run:

filename packages "/home/myuserid/SASpackages"; /* setup directory for packages */
%include packages(SPFinit.sas); /* enable the framework */

%loadPackage(BasePlus)    /* load the package content into the SAS session */

4) Enjoy 

 

P.S.2

No access to the internet on your machine? No problem! Instead step number 2 go here and manually download SPFinit.sas file. Then go to here and download baseplus.zip file. Store them in the directory from step 1 and proceed to step 3.

 

_______________
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



Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 829 views
  • 2 likes
  • 5 in conversation