Hi everyone,
I'm having a very strange problem. I have a program which refers to a zip file using a filename statement:
filename zip1 zip "&dir./&file..zip";
Then later, I try to read in a SAS file from within the zip file using the infile statement:
data _null_;
infile zip1(C:/dirname/filename.sas7bdat)
lrecl=256 recfm=F length=length eof=eof unbuf;
-other unrelated stuff-
run;
This works just fine. The issue is that I wanted to automatically generate the name of the SAS file. I set up a step to do this and it produces exactly the value I wanted (C:/dirname/filename.sas7bdat).
The issue is that the data _null_ step above will work if I use the value of the macro variable written out (C:/dirname/filename.sas7bdat), but will generate an error message if I substitute that with ¯ovar. I tried putting " " around ¯ovar (no help), and macrotizing just parts of the filepath (which worked fine, but I want to macrotize the whole thing).
The error message I get says that the SAS file does not exist within the zip file.
Any help is much appreciated!
data _null_;
set contents;
if index(memname, "arc") > 0 then
call symputx('fname', memname);
run;
%put &fname;
Can you run the following and post the log- note the change to call symputX - adding X.
filename zip1 zip "&dir./&file..zip";
filename ds "%sysfunc(getoption(work))/test.sas7bdat";
/* Read the "members" (files) from the ZIP file */
data contents (keep=memname isfolder);
length memname $200 isfolder 8;
fid=dopen("zip1");
if fid=0 then
stop;
memcount=dnum(fid);
do i=1 to memcount;
memname=dread(fid,i);
isFolder = (first(reverse(trim(memname)))='/');
output;
end;
rc=dclose(fid);
run;
data _null_;
set contents;
if index(memname, "arc") > 0 then
call symput('fname', memname);
run;
data _null_;
infile zip1(&fname)
lrecl=256 recfm=F length=length eof=eof unbuf;
file ds lrecl=256 recfm=N;
input;
put _infile_ $varying256. length;
return;
eof:
stop;
run;
data _null_;
set contents;
if index(memname, "arc") > 0 then
call symputx('fname', memname);
run;
%put &fname;
Can you run the following and post the log- note the change to call symputX - adding X.
Since your problem seems to be with the first statement of that code, the rest is irrelevant. What's really important is the code that creates the two macro variables &dir and &file. Please show us that.
And if your problem happens later here:
data _null_;
set contents;
if index(memname, "arc") > 0 then
call symput('fname', memname);
run;
you should use call symputx, as it trims leading and trailing blanks:
data _null_;
set contents;
if index(memname, "arc") > 0
then call symputx('fname', memname);
run;
Note that this will get you only the last entry in contents that satisfies the condition.
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: