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

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
  • 5 replies
  • 637 views
  • 0 likes
  • 2 in conversation