Hi,
I need the code to check whether the directory is empty in sas macro.
This should work
%macro isemptyfolder(folder);
%let filrf=mydir;
%let rc=%sysfunc(filename(filrf, "&folder"));
%let did=%sysfunc(dopen(&filrf));
%let memcount=%sysfunc(dnum(&did));
%let rc=%sysfunc(dclose(&did));
%put 'number of members in folder ' &folder ' = ' &memcount;
%mend isemptyfolder;
Please note this is a Q&A board, not a contract work request system. If you have a question, provide what you have done, show example code using the {i}. If you have access to the command line then doing a filename tmp pipe 'dir c:\test /b'; and using that in a datastep then checking that might work. Not sure what the benefit of checking for an empty directory is though, doesn't really add anything. Do you want to check existence of the folder, or maybe a file you don't want to overwrite?
This should work
%macro isemptyfolder(folder);
%let filrf=mydir;
%let rc=%sysfunc(filename(filrf, "&folder"));
%let did=%sysfunc(dopen(&filrf));
%let memcount=%sysfunc(dnum(&did));
%let rc=%sysfunc(dclose(&did));
%put 'number of members in folder ' &folder ' = ' &memcount;
%mend isemptyfolder;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.