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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.