- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello friends,
i have below programs that i created to delete few selected entire directories from specific dir (on linux system via EG).
this program running fine however, my goal is delete all directories that i have in test2 dataset (have like 15 dir under test) with "rm -rf" command but its just deleting one dir when i run it,
how can i tell SAS that perform all command (rm -rf) for all directory?
data test (keep=files);
length access $ 20 files $ 200;
infile "cd /test; ls -lt;" pipe firstobs=2;
input access $ nx $ user $ group $ size $ month $ day $ time $ files;
run;
/*creating rm -rf command*/
data test2;
set test;
rmcmd=catx(' ','rm -rf'
,cats('/test/',files);
run;
/*rmcmd variable looks like this*/
rmcmd
rm -rf sdfkjqfjnsvv
rm -rf skdfjspiu
rm -rf soivjasivuhqsvjnsvkjnsv
rm -rf sdlvjasvhqqdsdkvjbqsdvhb
/*trying to execute rm -rf commanf for all*/
data _null_;
set test2;
infile cmd pipe filevar=rmcmd;
input@;
run;
Thanks a lot...!!!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The easiest change is to use the FILEVAR option on the INFILE statement to execute the commands you have generated.
data test2;
set test;
rmcmd=catx(' ','rm -rf',cats('/test/',files));
run;
data _null_;
set test2 ;
infile cmd pipe filevar=rmcmd end=eof;
do while (not eof);
input;
put _infile_;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You might try the FDELETE function. You would not send the unix command just the name of the file and/or directory:
data _null_; set test2; rc=fdelete(fname); put rc=; msg=sysmsg(); put msg=; run;
where Fname above is just the name of the directory. The PUT statements show the results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
NOTE: In a call to the FDELETE routine, the fileref rm -rf
/test/sdfkjqfjnsvv exceeds 8 characters, and will be truncated.
rc=20004
msg=ERROR: No logical assign for filename RM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
the length for any character type variable needs to be set long enough to hand the explected values. For the FDELETE you do not want the "rm -rf" as part of the name string as that is not the actual file or directory name.
Another approach, would be the X or call system statements, IF you have permissions to run X. Since I'm not running on unix I can't really test what you may be attempting to provide more direct examples.
Something like this perhaps:
data _null_; set test2; call system(rmcmd); run;
Your pipe failing because INFILE is not really an executeable, as in it isnot called for each record in test2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The easiest change is to use the FILEVAR option on the INFILE statement to execute the commands you have generated.
data test2;
set test;
rmcmd=catx(' ','rm -rf',cats('/test/',files));
run;
data _null_;
set test2 ;
infile cmd pipe filevar=rmcmd end=eof;
do while (not eof);
input;
put _infile_;
end;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
needed that end=eof + do while statement
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why not simply use call system to execute the rm commands?
data _null_;
set test2;
call system(rmcmd);
run;
I'd suggest to use absolute path names for the files to be removed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I would like to make a shell file to contain all these command, and execute once for all. data _null_; file '/home/temp.sh'; put "rm -rf sdfkjqfjnsvv"; put "rm -rf skdfjspiu"; put "rm -rf soivjasivuhqsvjnsvkjnsv"; put "rm -rf sdlvjasvhqqdsdkvjbqsdvhb"; run; x "./home/temp.sh";