<?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: X statement has different return value in EG than it has in batch mode in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502612#M134194</link>
    <description>&lt;P&gt;Tank you or your reply. Even though I didn't really understand what the jobname has to do with SAS running grep on the linux box I think your answer pointed me into the right direction:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe "ps -ef|grep boxoffice|grep -v grep";

data _null_;
if eof then 
	do;
		put "Lines read:" _n_;
		if _n_ gt 1 then
			do;
				put "Another instance of this code is running, stopping execution";
				/*abort 255;*/
			end;
		else
			do;
				put "No other instance of this code is running, continuing";
			end;	
	end;
infile oscmd end=eof;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I had to put the check before the infile-statement because otherwise "if eof" wouldn't trigger when the file is empty (grep returned&amp;nbsp;0 lines), which means even if grep returns 0 lines _n_ will be 1. Is that the recommended way of working around that issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/edit: Ok, I got it now and I feel incredibly stupid... Of course the process finds itself when it is started by SMC.... I changed the code to gt 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all for your help!&lt;/P&gt;</description>
    <pubDate>Tue, 09 Oct 2018 08:38:43 GMT</pubDate>
    <dc:creator>dakes</dc:creator>
    <dc:date>2018-10-09T08:38:43Z</dc:date>
    <item>
      <title>X statement has different return value in EG than it has in batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502597#M134188</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote a bit of code to check whether the same code is already executing. If it was, stop the new run, if it doesn't start the new run as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro checkifrunning;
x ' ps -ef|grep boxoffice|grep -v grep';
%let rc=&amp;amp;sysrc ;
%put &amp;amp;=rc ;

%if &amp;amp;rc. eq 0 %then %do;
	%put Another instance of this code is running, stopping execution;
	%Abort Return;
	%end;
%else %do;
	%put No other instance of this code is running;
%end;

%put continuing execution;
%mend;
%checkifrunning;&lt;/PRE&gt;&lt;P&gt;A bit of background:&lt;/P&gt;&lt;PRE&gt;ps -ef|grep boxoffice|grep -v grep&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;On linux (which we run) this has a return code ($?) of 0 when the process (boxoffice) is running and 1 when it isn't. This works perfectly well when I run it in SAS Enterprise Guide., but when a run is started by SAS Management console the return code is always 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anybody tell me what I am doing wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 07:12:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502597#M134188</guid>
      <dc:creator>dakes</dc:creator>
      <dc:date>2018-10-09T07:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: X statement has different return value in EG than it has in batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502601#M134189</link>
      <description>&lt;P&gt;When you run the code in EG, the SAS process has no "jobname" in its commandline. The workspace server is started on demand from EG, but the current "program name" does only exist as a macro variable within the Base SAS environment.&lt;/P&gt;
&lt;P&gt;When you run it from SMC (scheduled), it runs in batch mode, and the program name &lt;EM&gt;will&lt;/EM&gt; be on the commandline, so the job finds itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write a test program, and use this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe "ps -ef|grep test.sas|grep -v grep";

data _null_;
infile oscmd;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to catch all output from your command. This will tell you how many lines the grep finds, from which you can design suitable code.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 07:32:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502601#M134189</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-09T07:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: X statement has different return value in EG than it has in batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502606#M134192</link>
      <description>&lt;P&gt;Have you checked the XCMD option on the SAS session that you start from the management console? If it is NOXCMD, that may explain the problem (the default value for &amp;amp;sysrc is 0, so you may get that if no X command is run).&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 07:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502606#M134192</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-09T07:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: X statement has different return value in EG than it has in batch mode</title>
      <link>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502612#M134194</link>
      <description>&lt;P&gt;Tank you or your reply. Even though I didn't really understand what the jobname has to do with SAS running grep on the linux box I think your answer pointed me into the right direction:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename oscmd pipe "ps -ef|grep boxoffice|grep -v grep";

data _null_;
if eof then 
	do;
		put "Lines read:" _n_;
		if _n_ gt 1 then
			do;
				put "Another instance of this code is running, stopping execution";
				/*abort 255;*/
			end;
		else
			do;
				put "No other instance of this code is running, continuing";
			end;	
	end;
infile oscmd end=eof;
input;
put _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I had to put the check before the infile-statement because otherwise "if eof" wouldn't trigger when the file is empty (grep returned&amp;nbsp;0 lines), which means even if grep returns 0 lines _n_ will be 1. Is that the recommended way of working around that issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/edit: Ok, I got it now and I feel incredibly stupid... Of course the process finds itself when it is started by SMC.... I changed the code to gt 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all for your help!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 08:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/X-statement-has-different-return-value-in-EG-than-it-has-in/m-p/502612#M134194</guid>
      <dc:creator>dakes</dc:creator>
      <dc:date>2018-10-09T08:38:43Z</dc:date>
    </item>
  </channel>
</rss>

