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;
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.
See this helpful macro
@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;
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;
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.
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?
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.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.