DATA Step, Macro, Functions and more

Check and delete windows directory

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Check and delete windows directory

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


Accepted Solutions
Solution
‎12-02-2016 04:02 AM
Super User
Super User
Posts: 7,942

Re: Check and delete windows directory

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


All Replies
Solution
‎12-02-2016 04:02 AM
Super User
Super User
Posts: 7,942

Re: Check and delete windows directory

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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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