Return value
For
shell commands, the return value of the
system
function can be used to determine if it executed successfully.
If it ran successfully, the return value is 0.
In the following example, the system function executes
ls
on a file. If the file does not exist,
ls
considers the command not successful and returns a value different from 0.
If this is the case, the exmple uses
call system
to create (
touch
) the file.
With another system
, it then checks wheter the file was created indeed, this time checking for the return value being 0.
data _null_;
log_file = '/tmp/tq84.log';
if system(cat('ls ', log_file)) <> 0 then do;
put log_file ' does not exist, creating it.';
call system (cat('touch ', log_file));
end;
/* */
if system(cat('ls ', log_file)) = 0 then do;
put log_file ' exists';
end;
run;