<?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: Open %IF / %ELSE to create part of a statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866176#M342060</link>
    <description>&lt;P&gt;Thanks, will submit it as a bug.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Mar 2023 15:49:09 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-03-24T15:49:09Z</dc:date>
    <item>
      <title>Open %IF / %ELSE to create part of a statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866158#M342053</link>
      <description>&lt;P&gt;I don't use an open (i.e. outside of macro definition) %IF much.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Today I was playing with open %IF for a communities question, and hit a problem where it looks like open %ELSE can't be used to generate part of a statement.&amp;nbsp; Feels like perhaps a bug?&amp;nbsp; Unless it's documented that open %IF/%ELSE shouldn't be used to generate part of a SAS statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This step won't compile (9.4M7):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 set 
   %if 0 %then %do ;
     sashelp.class
   %end ;
   %else %do ;
     sashelp.shoes
   %end ;
 ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The error is:&lt;/P&gt;
&lt;PRE&gt;480  data want ;
481   set
482     %if 0 %then %do ;
483       sashelp.class
484     %end ;
485     %else %do ;
486       sashelp.shoes
          -------------
          557
ERROR 557-185: Variable sashelp is not an object.

487     %end ;
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.
NOTE: The SAS System stopped processing this step because of errors.
488   ;
489  run ;
&lt;/PRE&gt;
&lt;P&gt;If I put the beginning of the SET statement in the %IF block it works.&amp;nbsp; But there is another oddity.&amp;nbsp; Below code works, even though there is no semicolon to end the SET statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 %if 0 %then %do ;
   set sashelp.class
 %end ;
 %else %do ;
   set sashelp.shoes
 %end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and below code will error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 %if 0 %then %do ;
   set sashelp.class
 %end ;
 %else %do ;
   set sashelp.shoes
 %end ;
 sashelp.cars ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Interestingly, the problem seems to be related to the code generated by the open %ELSE.&amp;nbsp; If I change the first %IF to %IF 1, then all of the above examples give the results I would expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
 set 
   %if 1 %then %do ;
     sashelp.class
   %end ;
   %else %do ;
     sashelp.shoes
   %end ;
 ;
run ;
&lt;BR /&gt;&lt;BR /&gt;*errors because of missing semicolon for SET statement;
data want ;
 %if 1 %then %do ;
   set sashelp.class
 %end ;
 %else %do ;
   set sashelp.shoes
 %end ;
run ;

data want ;
 %if 1 %then %do ;
   set sashelp.class
 %end ;
 %else %do ;
   set sashelp.shoes
 %end ;
 sashelp.cars &lt;BR /&gt; ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 15:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866158#M342053</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-24T15:18:44Z</dc:date>
    </item>
    <item>
      <title>Re: Open %IF / %ELSE to create part of a statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866161#M342054</link>
      <description>&lt;P&gt;Your exact code inside a macro works, so yes, your example does feel like a bug to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dothis;
data want ;
 set
   %if 0 %then %do ;
     sashelp.class
   %end ;
   %else %do ;
     sashelp.shoes
   %end ;
 ;
run ;
%mend;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2023 15:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866161#M342054</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-24T15:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Open %IF / %ELSE to create part of a statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866175#M342059</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works in Linux but not in Windows, so I think you are right in assuming it is a bug.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ErikLund_Jensen_0-1679672667987.png" style="width: 899px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82017iB39280E064F36F1A/image-dimensions/899x308?v=v2" width="899" height="308" role="button" title="ErikLund_Jensen_0-1679672667987.png" alt="ErikLund_Jensen_0-1679672667987.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 15:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866175#M342059</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-03-24T15:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Open %IF / %ELSE to create part of a statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866176#M342060</link>
      <description>&lt;P&gt;Thanks, will submit it as a bug.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 15:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866176#M342060</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-24T15:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Open %IF / %ELSE to create part of a statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866205#M342074</link>
      <description>&lt;P&gt;Support for open code %IF is very limited.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest using a macro variable so that you have complete statements inside the %DO/%END blocks.&lt;/P&gt;
&lt;PRE&gt;663  %if 0 %then %do ;
664    %let dsn=sashelp.class;
665  %end ;
666  %else %do ;
667    %let dsn=sashelp.shoes;
668  %end ;
669  data want ;
670   set &amp;amp;dsn ;
671  run ;

NOTE: There were 395 observations read from the data set SASHELP.SHOES.
NOTE: The data set WORK.WANT has 395 observations and 7 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 17:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866205#M342074</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-24T17:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Open %IF / %ELSE to create part of a statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866236#M342087</link>
      <description>&lt;P&gt;Heard back from Tech Support already.&amp;nbsp; Macro legend Russ Tyndall explained this is a known bug, already documented:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/kb/65/310.html" target="_blank"&gt;https://support.sas.com/kb/65/310.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2023 21:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866236#M342087</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-24T21:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Open %IF / %ELSE to create part of a statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866521#M342214</link>
      <description>&lt;P&gt;Russ updated me that the bug is fixed in 9.4M8.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Mar 2023 12:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Open-IF-ELSE-to-create-part-of-a-statement/m-p/866521#M342214</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-27T12:45:32Z</dc:date>
    </item>
  </channel>
</rss>

