BookmarkSubscribeRSS Feed
Soundappan
Fluorite | Level 6
Hi I am trying to add output[1].pdf file inside a dummy.zip file, but whenever i try to add I am getting an Error.(ERROR: Physical file does not exist, //sas_data/reports/test_bestd/output[1].pdf).
But the actual file exists and file permissions have no issue.

I am facing this issue only when the filename has Square brackets in it.

How can this be resolved ?

%let var = <SOURCELOC>/output[1].pdf;
%let projectDir = <ZIPFOLLOC>;
filename newfile "<ZIPFOLLOC>/test_&timestamp..zip" ;
data _null_;
   if (fexist('newfile')) then
    rc = fdelete('newfile');
run;
ods package(newzip) open nopf;
 data test;
  if %sysfunc(fileexist(&var))
   then do;
   put 'File exist';
    filename a "&var";
    ods package(newzip) add  file=%bquote(a) path ="/";
   end;
  else put 'File does not exist';
 run;
ods package(newzip) publish archive
properties(
archive_name="dummy.zip"
archive_path="&projectDir."
);
ods package(newzip)
close;
5 REPLIES 5
Kurt_Bremser
Super User

ods and filename are global statements which cannot be executed conditionally in a data step.

Use macro code instead (needs at least SAS 9.4M5, otherwise you have to define a macro):

%let var = <SOURCELOC>/output[1].pdf;
%let projectDir = <ZIPFOLLOC>;
filename newfile "<ZIPFOLLOC>/test_&timestamp..zip";

data _null_;
if (fexist('newfile')) then rc = fdelete('newfile');
run;

ods package(newzip) open nopf;

%if %sysfunc(fileexist(&var))
%then %do;
  filename a "&var";
  %put File exist;
  ods package(newzip) add file=%bquote(a) path ="/";
%end;
%if ^ (%sysfunc(fileexist(&var)))
%then %do;
  %put File does not exist;
%end;

ods package(newzip) publish archive
  properties(
  archive_name="dummy.zip"
  archive_path="&projectDir."
  )
;
ods package(newzip) close;

Please post the log of this (use the {i} button), if it does not work.

Soundappan
Fluorite | Level 6

Hi thanks for reply.

 

I have updated the code, and used macro instead of data statement.

This time as well the fexists returned output as 'File Exists' but failed at ODS Publish part.
I have attached the complete log.

 

MLOGIC(ZIP_FILE):  %IF condition %sysfunc(fileexist(&var)) is TRUE
SYMBOLGEN:  Macro variable VAR resolves to //sas_data/pmqa/dev/reports/test_bestd/output[1].pdf
MPRINT(ZIP_FILE):   filename a "//sas_data/pmqa/dev/reports/test_bestd/output[1].pdf";
MLOGIC(ZIP_FILE):  %PUT File exist
File exist
MPRINT(ZIP_FILE):   ods package(newzip) add file=a path ="/";
SYMBOLGEN:  Macro variable VAR resolves to //sas_data/pmqa/dev/reports/test_bestd/output[1].pdf
MLOGIC(ZIP_FILE):  %IF condition ^ (%sysfunc(fileexist(&var))) is FALSE
SYMBOLGEN:  Macro variable TIMESTAMP resolves to 20191212T082430
SYMBOLGEN:  Macro variable PROJECTDIR resolves to //sas_data/pmqa/dev/reports/test_bestd
MPRINT(ZIP_FILE):   ods package(newzip) publish archive properties( archive_name="test_20191212T082430.zip"
archive_path="//sas_data/pmqa/dev/reports/test_bestd" ) ;
NOTE: Writing NEWZIP file: //sas_data/pmqa/dev/reports/test_bestd/test_20191212T082430.zip
ERROR: Physical file does not exist, //sas_data/pmqa/dev/reports/test_bestd/output[1].pdf.
MPRINT(ZIP_FILE):   ods package(newzip) close;
MLOGIC(ZIP_FILE):  Ending execution.

Soundappan
Fluorite | Level 6

The Folder 'test_bestd' exists and fexists returned 'is available.'


MPRINT(ZIP_FILE):   data _null_;
MPRINT(ZIP_FILE):   if (fileexist('//sas_data/pmqa/dev/reports/test_bestd')) then put "is available";
MPRINT(ZIP_FILE):   run;
is available

NOTE: PROCEDURE| _DISARM|         STOP| _DISARM| 2019-12-12T14:46:51,528+00:00| _DISARM| WorkspaceServer| _DISARM| SAS| _DISARM| |
      _DISARM| 25595904| _DISARM| 21397504| _DISARM| 11| _DISARM| 11| _DISARM| 0| _DISARM| 1112| _DISARM| 0.000000| _DISARM|
      0.005092| _DISARM| 1891781211.523573| _DISARM| 1891781211.528665| _DISARM| 0.000000| _DISARM| | _ENDDISARM
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1859 views
  • 0 likes
  • 2 in conversation