BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jp007_uk
Fluorite | Level 6

I would like to check if a windows directory is empty, if so delete it otherwise end.

 

Is this possible via SAS Base 9.4 and Windows 7

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its possible, and there are a few options.  You could stream in a dir pipe (not tested):

filename tmp pipe 'dir "c:\temp" /b';

data _null_;

  infile tmp dlm="¬";

  input buffer $;

  if buffer="your dir" then found=1;

run;

 

Or you could do it in a macro:

http://www.sascommunity.org/wiki/Tips:Check_if_a_directory_exists

 

And to delete:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245893.htm

 

The question is, why.  I generally try to avoid doing OS manipulations through SAS, especially through macro, as an unresolved macro, or problem url could lead to all kinds of problems.  Most of the time I find there are systematci problems if your having to do this anyways.

View solution in original post

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its possible, and there are a few options.  You could stream in a dir pipe (not tested):

filename tmp pipe 'dir "c:\temp" /b';

data _null_;

  infile tmp dlm="¬";

  input buffer $;

  if buffer="your dir" then found=1;

run;

 

Or you could do it in a macro:

http://www.sascommunity.org/wiki/Tips:Check_if_a_directory_exists

 

And to delete:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000245893.htm

 

The question is, why.  I generally try to avoid doing OS manipulations through SAS, especially through macro, as an unresolved macro, or problem url could lead to all kinds of problems.  Most of the time I find there are systematci problems if your having to do this anyways.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 969 views
  • 1 like
  • 2 in conversation