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_×tamp..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.
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.
Run this to check if the directory is available:
data _null_;
if (fileexist('//sas_data/pmqa/dev/reports/test_bestd')) then put "is available";
run;
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
Have you tried to create the file without the square brackets?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.
Ready to level-up your skills? Choose your own adventure.