Closes a directory that was opened by the DOPEN function
Category: External Files
DCLOSE ( directory-id )
directory-id
specifies the identifier that was assigned when the directory was opened, generally by the DOPEN function.
DCLOSE returns 0 if the operation was successful, ‰ 0 if it was not successful. The DCLOSE function closes a directory that was previously opened by the DOPEN function. DCLOSE also closes any open members .
Note: All directories or members opened within a DATA step are closed automatically when the DATA step ends.
This example opens the directory to which the fileref MYDIR has previously been assigned, returns the number of members, and then closes the directory:
%macro memnum(filrf,path); %let rc=%sysfunc(filename(filrf,&path)); %if %sysfunc(fileref(&filrf)) = 0 %then %do; /* Open the directory. */ %let did=%sysfunc(dopen(&filrf)); %put did=&did; /* Get the member count. */ %let memcount=%sysfunc(dnum(&did)); %put &memcount members in &filrf.; /* Close the directory. */ %let rc= %sysfunc(dclose(&did)); %end; %else %put Invalid FILEREF; %mend; %memnum(MYDIR, physical-filename )
This example uses the DCLOSE function within a DATA step:
%let filrf=MYDIR; data _null_; rc=filename("&filrf"," physical-filename "); if fileref("&filrf") = 0 then do; /* Open the directory. */ did=dopen("&filrf"); /* Get the member count. */ memcount=dnum(did); put memcount "members in &filrf"; /* Close the directory. */ rc=dclose(did); end; else put "Invalid FILEREF"; run;
Functions:
'DOPEN Function' on page 503
'FCLOSE Function' on page 519
'FOPEN Function' on page 550
'MOPEN Function' on page 656