<?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: execute a shell script from unix sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389361#M93358</link>
    <description>Figure out the command required on UNIX first. &lt;BR /&gt;Then add the X or SYSEXEC in SAS. You do need to make sure you have privileges to do this as well.</description>
    <pubDate>Sat, 19 Aug 2017 23:57:33 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-08-19T23:57:33Z</dc:date>
    <item>
      <title>execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389356#M93357</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I run SAS code in UNIX. I have a shell script file( sortdata.sh ) need&amp;nbsp;to be called from this SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;May I ask how to coding it in detail in SAS to execute the .sh file? using&amp;nbsp;data _null_ step? or ..?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There maybe different methods can do this, any method will&amp;nbsp;be greatly appreciated!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;code maybe used:

a) X command
X 'sh /SASInt/.../sortdata.sh &amp;amp;';




b) %macro sample;
%sysexec %str(sh /SASInt/.../sortdata.sh &amp;amp;)'






c) filename results pipe "sh /SASInt/.../sortdata.sh &amp;amp;";&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2017 22:35:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389356#M93357</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-08-19T22:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389361#M93358</link>
      <description>Figure out the command required on UNIX first. &lt;BR /&gt;Then add the X or SYSEXEC in SAS. You do need to make sure you have privileges to do this as well.</description>
      <pubDate>Sat, 19 Aug 2017 23:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389361#M93358</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-08-19T23:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389370#M93360</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before you run the .sh file, you need to make it executable. Use X commands to run UNIX commands&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2017 02:11:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389370#M93360</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-08-20T02:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389382#M93364</link>
      <description>&lt;P&gt;I prefer the filename pipe method, as it enables me to catch all system output back into the SAS log. Don't forget to add&lt;/P&gt;
&lt;P&gt;2&amp;gt;&amp;amp;1&lt;/P&gt;
&lt;P&gt;to your command, to reroute stderr to stdout.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Aug 2017 06:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389382#M93364</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-20T06:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389429#M93370</link>
      <description>&lt;P&gt;data _null_;&lt;BR /&gt;call system ('cd /..../test');&lt;BR /&gt;call system ('sas test123.sas &amp;amp;');&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 00:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389429#M93370</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-08-21T00:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389431#M93371</link>
      <description>&lt;P&gt;You can put both commands in the same call system statement separated by a semi-colon as shown on this page&amp;nbsp;&lt;A href="http://support.sas.com/documentation/cdl/en/hostunx/69602/HTML/default/viewer.htm#p0w085btd5r0a4n1km4bcdpgqibt.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/hostunx/69602/HTML/default/viewer.htm#p0w085btd5r0a4n1km4bcdpgqibt.htm&lt;/A&gt; - you'll have to use a macro quoting function but at least that way you can be sure all commands execute inside the same UNIX shell.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 00:39:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389431#M93371</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-08-21T00:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389433#M93372</link>
      <description>&lt;P&gt;Thank you Kurt!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would you please tell me where to put the "2&amp;gt;&amp;amp;1" ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename results pipe "sh sortdata.sh &amp;amp;" 2&amp;gt;&amp;amp;1 ; /*this not work, do I need to put it in sh file?*/
data pip;
infile results pad missover lrecl=3;
input answer $50.;
put answer=;
run;
proc print _last_;
run;&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 00:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389433#M93372</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-08-21T00:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389457#M93381</link>
      <description>&lt;P&gt;Yes, the redirection is part of the UNIX command.&lt;/P&gt;
&lt;P&gt;The command should be&lt;/P&gt;
&lt;PRE&gt;"sh sortdata.sh 2&amp;gt;&amp;amp;1"&lt;/PRE&gt;
&lt;P&gt;Note that I also omitted your &amp;amp; (run job in background), as that would be counterproductive in catching all output.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 06:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389457#M93381</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-21T06:03:08Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389577#M93411</link>
      <description>&lt;P&gt;Thank you Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it must be a .sh file to use 2&amp;gt;&amp;amp;1 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if it is a sas file, I can't use this :&lt;/P&gt;
&lt;PRE&gt;"sas sortdata.sas 2&amp;gt;&amp;amp;1"&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 21 Aug 2017 16:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389577#M93411</guid>
      <dc:creator>GeorgeSAS</dc:creator>
      <dc:date>2017-08-21T16:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: execute a shell script from unix sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389726#M93456</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10531"&gt;@GeorgeSAS&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you Kurt,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it must be a .sh file to use 2&amp;gt;&amp;amp;1 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if it is a sas file, I can't use this :&lt;/P&gt;
&lt;PRE&gt;"sas sortdata.sas 2&amp;gt;&amp;amp;1"&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Can be anything runnable from the commandline.&lt;/P&gt;
&lt;P&gt;I wrote a quick program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sasuser.test;
x1 = datetime();
format x1 e8601dt22.;
put x1=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and stored it as test.sas in my home directory.&lt;/P&gt;
&lt;P&gt;Then I ran this from my EG session:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe "/sas/SASFoundation/9.4/sas $HOME/test.sas -altlog $HOME/test.log 2&amp;gt;&amp;amp;1";

data _null_;
infile oscmd;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I specified the whole path to the SAS executable, as we do not have that in the PATH environment variable.&lt;/P&gt;
&lt;P&gt;The log in EG shows this:&lt;/P&gt;
&lt;PRE&gt;24         filename oscmd pipe "/sas/SASFoundation/9.4/sas $HOME/test.sas -altlog $HOME/test.log 2&amp;gt;&amp;amp;1";
25         
26         data _null_;
27         infile oscmd;
28         input;
29         put _infile_;
30         run;

NOTE: The infile OSCMD is:
      Pipe-Kommando="/sas/SASFoundation/9.4/sas $HOME/test.sas -altlog $HOME/test.log 2&amp;gt;&amp;amp;1"

NOTE: 0 records were read from the infile OSCMD.
NOTE: DATA statement used (Total process time):
      real time           0.41 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;which indicates no message came back from the system.&lt;/P&gt;
&lt;P&gt;$HOME/test.log looks like this (excerpt):&lt;/P&gt;
&lt;PRE&gt;1          data sasuser.test;
2          x1 = datetime();
3          format x1 e8601dt22.;
4          put x1=;
5          run;

x1=2017-08-22T07:39:14
NOTE: The data set SASUSER.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;and dataset SASUSER.TEST shows this:&lt;/P&gt;
&lt;PRE&gt;x1

   2017-08-22T07:39:14
&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Aug 2017 05:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/execute-a-shell-script-from-unix-sas/m-p/389726#M93456</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-22T05:46:35Z</dc:date>
    </item>
  </channel>
</rss>

