I need a basic understanding of difference between DOPEN and fileexist functions.

Reply
New Contributor
Posts: 2

I need a basic understanding of difference between DOPEN and fileexist functions.

Need to know the difference between DOPEN and FILEEXIST functions.

My requirement is to check if a directory exist and if it exist then need to read a file in the directory using a data step.

I used FILEEXIST function to fix a bug, in a code where already DOPEN is used to check the directory existance. Can this modify the operation of the code.?

Super User
Posts: 19,156

Re: I need a basic understanding of difference between DOPEN and fileexist functions.

RTM

Fileexist:

Verifies the existence of an external file by its physical name.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition


DOPEN:

Opens a directory, and returns a directory identifier value.

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

Super User
Super User
Posts: 6,845

Re: I need a basic understanding of difference between DOPEN and fileexist functions.

FILEEXIST() will check if the path you have provided exists, but it does not tell whether that path is a regular file or a directory.

DOPEN() will attempt to actually open the path as a directory and so will fail if it is instead a regular file.

Super User
Super User
Posts: 6,845

Re: I need a basic understanding of difference between DOPEN and fileexist functions.

>> My requirement is to check if a directory exist and if it exist then need to read a file in the directory using a data step.

Why not just test if the file exists?  If the directory doesn't exist then the file won't exist.  And if the file doesn't exist what do you care whether the directory exists or not?

New Contributor
Posts: 4

Re: I need a basic understanding of difference between DOPEN and fileexist functions.

thanks for the answers

Ask a Question
Discussion stats
  • 4 replies
  • 207 views
  • 1 like
  • 4 in conversation