Short answer: you can't do that.
Longer answer:
When you run SAS from a shell script, the shell forks off a copy of itself that will run the SAS command via the exec() system call. What you manipulate is therefore the environment of a child of the shell that runs the shell script. Since the child has no access to the parent's environment, changes will be lost when the child terminates.
Possible workarounds:
- save the setting of the environment variable to a file and source that in the shell script:
SAS:
data _null_;
file '$HOME/tempscript';
put "VAR=xxx";
run;
shell script:
sas program.sas
. $HOME/tempscript
rm $HOME/tempscript
- you can set return codes with
abort return &rc.;
and evaluate them in the script
sas program.sas
RC=$?
BTW, do test external commands from the commandline before using them in an x statement.
AFAIK, setenv() is a system call (ie for C programming), but not a system command.
... View more