As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

Tips Talk:Check if a directory exists

From sasCommunity
Jump to: navigation, search

good tip
The FILEEXIST function eliminates the need to create the FILEREF first (which should then be cleared)

   %if %sysfunc(fileexist(&dir))  %then %let return=1;    
   %else %let return=0;
--Art Carpenter 18:02, 7 January 2011 (UTC)

It's true! Thanks! --Adrien VALLEE 13:57, 10 January 2011 (UTC)

Since the return values are 0/1, why not simplify as follows:

%macro DirExist(dir) ; 
%mend DirExist;

And point out that this use of macro is simply a wrapper to hide the use of %sysfunc. --Don Henderson 01:51, 17 January 2011 (UTC)

This does not differentiate between a directory and a file. It will return 1 if a file of the specified name exists. -- Jon Williamson 15 Apr 2014

Correct, but since the filename and the doc emphasize that use, the point of this tip is to highlight that it works for directories as well.--Don Henderson (talk) 06:52, 22 April 2014 (CDT)

With the extra info via the read more, good tip. Also added a phrase about files and directories and added a see also link for the fexist function. --Don Henderson (talk) 06:52, 22 April 2014 (CDT)