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


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


Difference between revisions of "Does the Directory Exist"

From sasCommunity
Jump to: navigation, search
(add (archived) link about creating a folder, if it doesn't already exist)
m (added a link - gardening)
 
Line 29: Line 29:
 
== External links ==
 
== External links ==
 
* [http://web.archive.org/web/20160526040359/http://www.sas.com/offices/europe/uk/support/sas-hints-tips/ht1_mar04.html How to Check if a Directory Already Exists and if not, Create it] from SAS.com
 
* [http://web.archive.org/web/20160526040359/http://www.sas.com/offices/europe/uk/support/sas-hints-tips/ht1_mar04.html How to Check if a Directory Already Exists and if not, Create it] from SAS.com
 +
* The paper[[Building Intelligent Macros: Using Metadata Functions with the SAS Macro Language|Building Intelligent Macros: Using Metadata Functions with the SAS Macro Language]] contains a description of the %CHECKLOC macro to check for the existence of a directory and create it if it does not already exist.
  
 
[[Category:FILENAME Function]]
 
[[Category:FILENAME Function]]

Latest revision as of 01:22, 28 February 2017

There are several ways to check to see if a directory (or a file) exists. These include the use of functions and often, though not necessarily, the macro language.

In the tip Tips:Check if a directory exists Adrien VALLEE demonstrates a macro that uses the FILENAME and FEXIST functions.

Additional discussion of that tip includes other approaches.

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)


Since the return values are 0/1, we can further simplify as follows:

%macro DirExist(dir) ; 
   %sysfunc(filename(fileref,&dir)) 
%mend DirExist;

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

In this final case the parameter could be a file as well as a directory.

External links