BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Walternate
Obsidian | Level 7

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 &macrovar. I tried putting " " around &macrovar (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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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.

View solution in original post

4 REPLIES 4
Reeza
Super User
Show your code that isn't working.
Walternate
Obsidian | Level 7

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;

 

Reeza
Super User
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.

Kurt_Bremser
Super User

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.

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!
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.

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
  • 4 replies
  • 694 views
  • 2 likes
  • 3 in conversation