Reputation: 87
How can I check if directory exists and if not, it would be then: syserr <>0?, I need
%sysfunc(filename(fileref,&dir))
I need the syserr value if exists 0 if not <>0. thanks for help
Upvotes: 3
Views: 7395
Reputation: 353
A cleaner method to check if a folder exists
%let does_it_exist=%sysfunc(fileexist(&dir));
This returns a value of 0 if the folder does not exist, and a value of 1 if the folder does exist.
Upvotes: 6
Reputation: 1120
There may be a cleaner way of getting SAS to throw an error, but the following worked for me. The general idea is that, if the directory exists, you do something that keeps syserr set to 0; if not, you do something that throws an error.
%let your_path = "...";
%macro your_macro(dir);
%let rc = %sysfunc(filename(fileref, &dir.));
%if %sysfunc(fexist(&fileref)) %then %do;
data _null_;
set _null_;
run;
%end;
%else %do;
data _null_;
set something_that_doesnt_exist;
run;
%end;
%put syserr = &syserr.;
%mend your_macro;
%your_macro(&your_path.);
Upvotes: 3