BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Super User

In UNIX, you can remove a file even when it's opened by a user. This is possible because the main metadata of the file (owner, group, date modified, data blocks) is kept in a so-called "inode" in a separate table (not in the directory entry as Windows does it). Removing a file in UNIX removes the directory entry (called "link"), but the file itself is only deleted once no further links exist and the last open handle on the inode is closed.

Since the system might want confirmation of the remove, you should use the -f option (for "force") in the rm command.

Super User

I do have a utility macro for this that basically looks like this:

%macro del_file(ext_file);
%if %sysfunc(fileexist(&ext_file.))
%then %do;
filename delfile pipe "rm -f &ext_file. 2>&1";
data _null_;
infile delfile;
put _infile_;

The macro will do the remove only when the file exists, and record all responses from the remove command in the SAS log.

Opal | Level 21


Looks like it worked Smiley Happy


Below an alternative way to issue the mv command.

This coding approach has the advantage that you'll get all the return messages from the command back into the SAS log (untested again because my current environment has NOXCMD set).

data _null_;
  cmd='mv -f ~/test_new.txt ~/test_orig.txt';
  infile mv pipe filevar=cmd end=eof;
  while (not eof);
    input ;
    put _infile_;


Super User Tom
Super User

Note that there is no need to wrap a data step around an X command.  The X statement is GLOBAL,like a TITLE statement, so it can be placed anywhere.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 18 replies
  • 5 in conversation