<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading the value of a macro variable sas from a shell script in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Reading-the-value-of-a-macro-variable-sas-from-a-shell-script/m-p/388404#M25039</link>
    <description>&lt;P&gt;Short answer: you can't do that.&lt;/P&gt;
&lt;P&gt;Longer answer:&lt;/P&gt;
&lt;P&gt;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 &lt;U&gt;child&lt;/U&gt; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Possible workarounds:&lt;/P&gt;
&lt;P&gt;- save the setting of the environment variable to a file and source that in the shell script:&lt;/P&gt;
&lt;P&gt;SAS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file '$HOME/tempscript';
put "VAR=xxx";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;shell script:&lt;/P&gt;
&lt;PRE&gt;sas program.sas
. $HOME/tempscript
rm $HOME/tempscript&lt;/PRE&gt;
&lt;P&gt;- you can set return codes with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;abort return &amp;amp;rc.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and evaluate them in the script&lt;/P&gt;
&lt;PRE&gt;sas program.sas
RC=$?&lt;/PRE&gt;
&lt;P&gt;BTW, do test external commands from the commandline before using them in an x statement.&lt;/P&gt;
&lt;P&gt;AFAIK, setenv() is a system call (ie for C programming), but not a system command.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Aug 2017 11:16:33 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-08-16T11:16:33Z</dc:date>
    <item>
      <title>Reading the value of a macro variable sas from a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Reading-the-value-of-a-macro-variable-sas-from-a-shell-script/m-p/388395#M25038</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to read the value of a macro variable sas from my shell script&amp;nbsp;&lt;/P&gt;&lt;P&gt;code SAS&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rc1=&amp;amp;x ;
x setenv var &amp;amp;rc1.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Shell script&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;period_ex=$(date --date='30 days ago' +%Y%m)
/sas/sasbin/SASFoundation/9.4/sas -sysin /sasdata/04_code_sas/0102_Flux_Client_sas.sas -autoexec /sasdata/04_code_sas/0100_autoexec.sas -NOPRINT -nosyntaxcheck -noerrabend -log /sasdata/07_logs/0102_Flux_Client_sas_$(date +"%Y%m%d_%H%M%S").log -SYSPARM $period_ex%$(date +"%Y%m%d_%H%M%S") -XCMD 
echo $var&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but the value is empty&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me please&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 09:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Reading-the-value-of-a-macro-variable-sas-from-a-shell-script/m-p/388395#M25038</guid>
      <dc:creator>Asmam</dc:creator>
      <dc:date>2017-08-16T09:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading the value of a macro variable sas from a shell script</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Reading-the-value-of-a-macro-variable-sas-from-a-shell-script/m-p/388404#M25039</link>
      <description>&lt;P&gt;Short answer: you can't do that.&lt;/P&gt;
&lt;P&gt;Longer answer:&lt;/P&gt;
&lt;P&gt;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 &lt;U&gt;child&lt;/U&gt; 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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Possible workarounds:&lt;/P&gt;
&lt;P&gt;- save the setting of the environment variable to a file and source that in the shell script:&lt;/P&gt;
&lt;P&gt;SAS:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
file '$HOME/tempscript';
put "VAR=xxx";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;shell script:&lt;/P&gt;
&lt;PRE&gt;sas program.sas
. $HOME/tempscript
rm $HOME/tempscript&lt;/PRE&gt;
&lt;P&gt;- you can set return codes with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;abort return &amp;amp;rc.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and evaluate them in the script&lt;/P&gt;
&lt;PRE&gt;sas program.sas
RC=$?&lt;/PRE&gt;
&lt;P&gt;BTW, do test external commands from the commandline before using them in an x statement.&lt;/P&gt;
&lt;P&gt;AFAIK, setenv() is a system call (ie for C programming), but not a system command.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 11:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Reading-the-value-of-a-macro-variable-sas-from-a-shell-script/m-p/388404#M25039</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-16T11:16:33Z</dc:date>
    </item>
  </channel>
</rss>

