Tips:Check if a directory exists

From sasCommunity
Revision as of 16:05, 27 February 2017 by Paulkaefer (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This macro returns 1 if the specified directory exists, 0 if not. It takes advantage of the fact that the fexist can check for the existence of both directories and files.

%macro DirExist(dir) ; 
   %LOCAL rc fileref return; 
   %let rc = %sysfunc(filename(fileref,&dir)) ; 
   %if %sysfunc(fexist(&fileref))  %then %let return=1;    
   %else %let return=0;
   &return
%mend DirExist;
/* Usage */
option noxwait; /* SAS 8.2 only */
%put %DirExist(C:\Documents and Settings\);
%put %DirExist(aaa);

....read more

....see also

Submitted by Adrien VALLEE. Contact me at my Discussion Page.