Search code examples
zipsasfilenamessas-ods

SAS - ODS zip file issue - no logical assign?


I'm having issues with the foloowing code and I can't seem to find much information to help me sort it out. I'm trying to write some filenames from a directory to a datset, then create a zip file of those files. It works fine until I reach the data step with the infile statement. I received the following error...

ERROR: No logical assign for filename DIRLIST.

Here is my code...

    %macro get_filenames(location);
    filename _dir_ "%bquote(&location.)";
    data filenames(keep=fname);
  handle=dopen( '_dir_' );
  if handle > 0 then do;
    count=dnum(handle);
    do i=1 to count;
      fname=dread(handle,i);
      output filenames;
    end;
  end;
  rc=dclose(handle);

run;
filename _dir_ clear;
%mend;

%get_filenames(c:\temp\);           

data dirlist;
 set filenames;
 where fname like 'scra%.txt';
run;

ods package(testfile) open nopf;

data _null_;
    infile dirlist pad lrecl=80;
    input @1 filename $80.;
    call execute
        (catx
            (' ',
            'ods package(testfile)',
            'add file=',
            quote('c:\temp\' || trim(filename)),
            ';'
            )
        );
run;

ods package(testfile) publish archive
properties(archive_name='testfile.zip'
archive_path='c:\temp\' );


ods package(testfile) close;

Solution

  • I think SAS is complaining about the following in your code:

    data _null_;
        infile dirlist pad lrecl=80;
    

    Infile in this context is expecting a FILENAME reference the kind you have at filename _dir_ "%bquote(&location.)"; It does not understand that you want to use the dataset dirlist.

    Replace the above code snippet with the following:

    data _null_;
        SET dirlist;