<?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: Executing a .sas program conditionally as part of a IF/THEN/DO/ELSE/DO loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517382#M139863</link>
    <description>&lt;P&gt;There are a few ways of doing this. Here is one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname datalib '/users/data/lives/here';

%let run_pgm =;

data datalib.c;
merge datalib.a datalib.b;
if varfroma=varfromb then do;
put 'BOTH VARIABLES ARE EQUAL';
call symput('run_pgm', '%include "sas /users/prog/lives/here/runme.sas";');
end;
else do;
put 'VARIABLES ARE UNEQUAL';
end;
run;

&amp;amp;run_pgm&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 30 Nov 2018 07:18:21 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2018-11-30T07:18:21Z</dc:date>
    <item>
      <title>Executing a .sas program conditionally as part of a IF/THEN/DO/ELSE/DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517372#M139858</link>
      <description>&lt;P&gt;The logic in the attached code block is working with the exception of the X command. Ideally, the X command to execute another SAS program should only run if varfroma=varfromb, but it keeps running even when varfroma ne varfromb. The put statements work properly, but the X command keeps running regardless of whether or not varfroma and varfromb are equal and seems to ignore the if/then/do logic. Can anyone suggest a way to fix this issue? Thanks.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname datalib '/users/data/lives/here';
data datalib.c;
merge datalib.a datalib.b;
if varfroma=varfromb then do;
put 'BOTH VARIABLES ARE EQUAL';
x 'sas /users/prog/lives/here/runme.sas';
end;
else do;
put 'VARIABLES ARE UNEQUAL';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 06:15:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517372#M139858</guid>
      <dc:creator>ijmoorejr</dc:creator>
      <dc:date>2018-11-30T06:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a .sas program conditionally as part of a IF/THEN/DO/ELSE/DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517375#M139860</link>
      <description>&lt;P&gt;Afaik the x command can't be executed conditionally. And it is a bit strange to call a sas program in a sas program using os-commands. What are you trying to do? You could, of course, replace the x command with call system.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 06:31:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517375#M139860</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-11-30T06:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a .sas program conditionally as part of a IF/THEN/DO/ELSE/DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517382#M139863</link>
      <description>&lt;P&gt;There are a few ways of doing this. Here is one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname datalib '/users/data/lives/here';

%let run_pgm =;

data datalib.c;
merge datalib.a datalib.b;
if varfroma=varfromb then do;
put 'BOTH VARIABLES ARE EQUAL';
call symput('run_pgm', '%include "sas /users/prog/lives/here/runme.sas";');
end;
else do;
put 'VARIABLES ARE UNEQUAL';
end;
run;

&amp;amp;run_pgm&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Nov 2018 07:18:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517382#M139863</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-11-30T07:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a .sas program conditionally as part of a IF/THEN/DO/ELSE/DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517387#M139866</link>
      <description>&lt;P&gt;Thank you, andreas_lds. Using call system worked.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 08:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517387#M139866</guid>
      <dc:creator>ijmoorejr</dc:creator>
      <dc:date>2018-11-30T08:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Executing a .sas program conditionally as part of a IF/THEN/DO/ELSE/DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517403#M139877</link>
      <description>&lt;P&gt;First of all, X is not a &lt;EM&gt;data step&lt;/EM&gt; statement, but a &lt;EM&gt;global&lt;/EM&gt; statement. Which means it takes effect immediately when it is encountered in the program text, not when that program text is executed after compilation.&lt;/P&gt;
&lt;P&gt;Your code is equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x 'sas /users/prog/lives/here/runme.sas';
data datalib.c;
merge datalib.a datalib.b;
if varfroma=varfromb then do;
put 'BOTH VARIABLES ARE EQUAL';
end;
else do;
put 'VARIABLES ARE UNEQUAL';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also mind: if you use call system here (which &lt;EM&gt;is&lt;/EM&gt; a data step call routine), you would execute the external program for EVERY mismatch, which is probably not what you want.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2018 09:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Executing-a-sas-program-conditionally-as-part-of-a-IF-THEN-DO/m-p/517403#M139877</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-30T09:21:28Z</dc:date>
    </item>
  </channel>
</rss>

