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...!!!
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;
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.
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.
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;
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.
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";
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.