BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kurt_Bremser
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.

Kurt_Bremser
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;
input;
put _infile_;
run;
%end;
%mend;

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

Patrick
Opal | Level 21

@Suzy_Cat 

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_;
  end;
  stop;
run;

 

Tom
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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 972 views
  • 10 likes
  • 5 in conversation