<?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: How do I fix: ERROR 22-322: Syntax error with &amp;quot;else if... then do...&amp;quot; statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730320#M227396</link>
    <description>&lt;P&gt;You need a semicolon after &lt;EM&gt;do&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Mar 2021 07:55:12 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-03-31T07:55:12Z</dc:date>
    <item>
      <title>How do I fix: ERROR 22-322: Syntax error with "else if... then do..." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730211#M227360</link>
      <description>&lt;P&gt;I keep receiving this error message:&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasError focus-line"&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, BY, EQ, GE, GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, TO, ^=, |, ||, ~=.&lt;/DIV&gt;&lt;DIV class="sasError focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError focus-line"&gt;The code is:&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError focus-line"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError focus-line"&gt;&lt;DIV class=" block-mark"&gt;&lt;SPAN class="sec-keyword"&gt;data&lt;/SPAN&gt;&lt;SPAN class="text"&gt; ex7&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;INFILE&lt;/SPAN&gt; &lt;SPAN class="string"&gt;"12q19.character.txt"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;dlm&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="hex"&gt;'09'x&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;firstobs&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;2&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="text"&gt; HOUSE Y X1 X2 X3 X4 location &lt;/SPAN&gt;&lt;SPAN class="sep"&gt;$;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;if&lt;/SPAN&gt;&lt;SPAN class="text"&gt; location&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string"&gt;"intown"&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;then&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;DO&lt;/SPAN&gt;&lt;SPAN class="text"&gt; Zlocation1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation2&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation3&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;end&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;if&lt;/SPAN&gt;&lt;SPAN class="text"&gt; location&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string"&gt;"inner suburbs"&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;then&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;DO&lt;/SPAN&gt;&lt;SPAN class="text"&gt; Zlocation1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;​;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation2&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;​;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation3&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;​;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;end&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;if&lt;/SPAN&gt;&lt;SPAN class="text"&gt; location&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string"&gt;"outer suburbs"&lt;/SPAN&gt; &lt;SPAN class="keyword"&gt;then&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;DO&lt;/SPAN&gt;&lt;SPAN class="text"&gt; Zlocation1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation2&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation3&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;end&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;else&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;do&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation2&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;0&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;Zlocation3&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="numeric"&gt;1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="keyword"&gt;end&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;x1location1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="text"&gt;x1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;*&lt;/SPAN&gt;&lt;SPAN class="text"&gt;Zlocation1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;x1location2&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="text"&gt;x1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;*&lt;/SPAN&gt;&lt;SPAN class="text"&gt;Zlocation2&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="text"&gt;x1location3&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;=&lt;/SPAN&gt;&lt;SPAN class="text"&gt;x1&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;*&lt;/SPAN&gt;&lt;SPAN class="text"&gt;Zlocation3&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN class="sec-keyword"&gt;run&lt;/SPAN&gt;&lt;SPAN class="sep"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This is where the error message is:&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="btenney_0-1617140399599.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56681iE641B4610FCB6A93/image-size/medium?v=v2&amp;amp;px=400" role="button" title="btenney_0-1617140399599.png" alt="btenney_0-1617140399599.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 30 Mar 2021 21:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730211#M227360</guid>
      <dc:creator>btenney</dc:creator>
      <dc:date>2021-03-30T21:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix: ERROR 22-322: Syntax error with "else if... then do..." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730214#M227362</link>
      <description>&lt;P&gt;Looks like there are gibberish characters before the semi-colon on some of the lines:&lt;/P&gt;
&lt;PRE&gt;502   else if location="inner suburbs" then
503   DO Zlocation1=1?;
                     -
                     388
                     200
                     76
504   Zlocation2=0?;
                  -
                  388
                  200
                  76
505   Zlocation3=0?;
                  -
                  388
                  200
                  76
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

506   end;
&lt;/PRE&gt;
&lt;P&gt;Also that is a very strange way to code your DO loop.&amp;nbsp; You have essentially coded an iterative DO loop with only one iteration.&amp;nbsp; Instead of using &lt;FONT face="courier new,courier"&gt;DO ZLOCATION1=0 to 2&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;DO ZLOCATION1=1,3,4&lt;/FONT&gt; you just have used&amp;nbsp;&lt;FONT face="courier new,courier"&gt;DO ZLOCATION1=0&lt;/FONT&gt;. Normally when you only want to run the DO loop once you do NOT include a iterative variable in the DO statement. Instead just use DO without anything after it and set ZLOCATION1 the same way you are setting ZLOCATION2 and ZLOCATION3.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if location="intown" then DO;
  Zlocation1=0;
  Zlocation2=0;
  Zlocation3=0;
end;
else if location="inner suburbs" then DO;
  Zlocation1=1;
  Zlocation2=0;
  Zlocation3=0;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From your logic it looks like you can eliminate the DO loops and the IF/THEN/ELSE statements and just calculate the 0/1 values as the result of boolean expressions.&amp;nbsp; Your current logic reduces to these three assignment statements.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Zlocation1=location="inner suburbs";
Zlocation2=location="outer suburbs";
Zlocation3=location not in ("intown" "inner suburbs" "outer suburbs");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 00:36:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730214#M227362</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-31T00:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix: ERROR 22-322: Syntax error with "else if... then do..." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730320#M227396</link>
      <description>&lt;P&gt;You need a semicolon after &lt;EM&gt;do&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 07:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730320#M227396</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-31T07:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I fix: ERROR 22-322: Syntax error with "else if... then do..." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730326#M227402</link>
      <description>&lt;P&gt;Maxim 12: &lt;STRONG&gt;Make It Look Nice&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;As posted, your code is hard to debug and maintain. This may have been caused by pasting the code into the main posting window. Use the "little running man" button right next to the one indicated for posting code:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54552i914D97BE1B0F21E5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;(&amp;lt;/&amp;gt; is for posting logs and other fixed-width text, e.g. content of text infiles)&lt;/P&gt;
&lt;P&gt;Next, replace the IF/THEN/ELSE IF chain with a SELECT block that better shows the purpose.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ex7;
infile
  "12q19.character.txt"
  dlm='09'x
  firstobs=2
;
input HOUSE Y X1 X2 X3 X4 location :$13.;
select (location);
  when ("intown") do;
    Zlocation1 = 0;
    Zlocation2 = 0;
    Zlocation3 = 0;
  end;
  when ("inner suburbs") do;
    Zlocation1 = 1;
    Zlocation2 = 0;
    Zlocation3 = 0;
  end;
  when ("outer suburbs") do;
    Zlocation1 = 0;
    Zlocation2 = 1;
    Zlocation3 = 0;
  end;
  otherwise do;
    Zlocation1 = 0;
    Zlocation2 = 0;
    Zlocation3 = 1;
  end;
end;
x1location1 = x1 * Zlocation1;
x1location2 = x1 * Zlocation2;
x1location3 = x1 * Zlocation3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There were some undisplayable characters where the ERROR was indicated.&lt;/P&gt;
&lt;P&gt;I also added an informat for the character variable. The $ sign on its own would lead to a defined length of 8, so the values "inner suburbs" and "outer suburbs" would be truncated during the read.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 08:19:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-fix-ERROR-22-322-Syntax-error-with-quot-else-if-then-do/m-p/730326#M227402</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-31T08:19:28Z</dc:date>
    </item>
  </channel>
</rss>

