<?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: code error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812869#M320746</link>
    <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;PRE&gt; 69         Data results.salary2;
 70         *Set cert.salary1;
 71         Do until (salary&amp;gt;=500000);
 72         Salary=256000.45
 73         Salary *0.0565 ;
            ______
            22
 ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, 
               LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.  
 
&lt;/PRE&gt;
&lt;P&gt;The SAS data step provides a SUM statement (e.g. salary + x;), but not a MULT statement.&lt;/P&gt;
&lt;P&gt;So your statement must be a complete assignment statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;salary = salary * 0.0565;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bu then, your code would run into an infinite loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until (salary &amp;gt;= 500000);
  salary = 256000.45;
  salary = salary * 0.0565;
  year + 1;
end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At the end of the loop, salary would always be&amp;nbsp;256000.45 *&amp;nbsp;0.0565, so it will never change.&lt;/P&gt;
&lt;P&gt;Now, even if you move the initialization before the loop&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;salary = 256000.45;
do until (salary &amp;gt;= 500000);
  salary = salary * 0.0565;
  year + 1;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will still get an infinite loop, as the multiplication will&amp;nbsp;&lt;EM&gt;lower&lt;/EM&gt; the value of salary, so it again never reaches the termination value.&lt;/P&gt;
&lt;P&gt;If you want to increase a value by 5.65 %, you need to multiply the value by 1.0565.&lt;/P&gt;</description>
    <pubDate>Thu, 12 May 2022 08:07:23 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-05-12T08:07:23Z</dc:date>
    <item>
      <title>code error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812789#M320708</link>
      <description>&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Hello, &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;I have a sas data set called salary1 in the library called cert with 1 observation and 2 variables (salary and year). I want to create an output salary2 in the library called results by increasing salary by 5.65% until I have $500.000. The value of salary =256000.45 and year=2022. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;I get an error message when I submit the code below. The error is on ‘Salary *0.0565’&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Data results.salary2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Set cert.salary1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Do until (salary&amp;gt;=500000);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Salary=256000.45&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Salary *0.0565 ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Year + 1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;End ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Proc print data = results.salary2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Run ; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Calibri" color="#000000"&gt;Any help?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 20:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812789#M320708</guid>
      <dc:creator>jeankoutou</dc:creator>
      <dc:date>2022-05-11T20:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: code error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812800#M320711</link>
      <description>&lt;P&gt;As you have discovered, this statement is invalid:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Salary *0.0565 ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In addition, your logic requires a tweak.&amp;nbsp; The initial value must be set before entering a loop.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data results.salary2;
Set cert.salary1;
Salary = 256000.45;&lt;BR /&gt;Year = 0;
Do until (salary&amp;gt;=500000);
  Salary = Salary *0.0565 ;
  Year + 1;
end ;
run;
Proc print data = results.salary2;
Run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally, note that SALARY begins with the same value on each observation.&amp;nbsp; (Perhaps that is a mistake assigning SALARY a value and the actual SALARY should be read from the input data set.)&amp;nbsp; At any rate, the final value for SALARY and YEAR will be unchanging from one observation to the next.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 20:34:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812800#M320711</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-05-11T20:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: code error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812838#M320731</link>
      <description>&lt;P&gt;Here are some additional explanations and modified code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS basically uses the form "variable=value to be assigned;" when assigning a value to a variable.&lt;/P&gt;
&lt;P&gt;In the following, the assignment is correct, but the semicolon at the end of the statement is missing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Salary=256000.45&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message is missing the semicolon at the end of the statement, so the next line is considered a single statement, and you see a keyword in the error message that connects Salary to 256000.45 as "&lt;FONT color="#FF0000"&gt;expecting one of the following: !, !!, &amp;amp;, *, **, +, -,...&lt;/FONT&gt;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Salary=256000.45 Salary *0.0565 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Also, the following does not match the syntax "variable=value to be assigned;" which is problematic.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Salary *0.0565 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Therefore, the following needs to be corrected&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Salary=Salary*0.0565 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, you said " by increasing salary by 5.65% ".&lt;BR /&gt;So I think the following should be written here&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Salary=Salary+Salary*0.0565 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Note that the following statement is "sum statement", which is a special statement to calculate the sum between obs, so there is no syntax problem.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Year + 1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest this code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results.salary2;
  set cert.salary1;
  do until (salary&amp;gt;=500000);
    Salary = Salary + Salary * 0.0565 ;
    Year + 1;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 01:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812838#M320731</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-05-12T01:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: code error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812869#M320746</link>
      <description>&lt;P&gt;Maxim 2: Read the Log.&lt;/P&gt;
&lt;PRE&gt; 69         Data results.salary2;
 70         *Set cert.salary1;
 71         Do until (salary&amp;gt;=500000);
 72         Salary=256000.45
 73         Salary *0.0565 ;
            ______
            22
 ERROR 22-322: Syntaxfehler, erwartet wird eines der folgenden: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, GT, 
               LE, LT, MAX, MIN, NE, NG, NL, OR, ^=, |, ||, ~=.  
 
&lt;/PRE&gt;
&lt;P&gt;The SAS data step provides a SUM statement (e.g. salary + x;), but not a MULT statement.&lt;/P&gt;
&lt;P&gt;So your statement must be a complete assignment statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;salary = salary * 0.0565;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bu then, your code would run into an infinite loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do until (salary &amp;gt;= 500000);
  salary = 256000.45;
  salary = salary * 0.0565;
  year + 1;
end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At the end of the loop, salary would always be&amp;nbsp;256000.45 *&amp;nbsp;0.0565, so it will never change.&lt;/P&gt;
&lt;P&gt;Now, even if you move the initialization before the loop&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;salary = 256000.45;
do until (salary &amp;gt;= 500000);
  salary = salary * 0.0565;
  year + 1;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you will still get an infinite loop, as the multiplication will&amp;nbsp;&lt;EM&gt;lower&lt;/EM&gt; the value of salary, so it again never reaches the termination value.&lt;/P&gt;
&lt;P&gt;If you want to increase a value by 5.65 %, you need to multiply the value by 1.0565.&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2022 08:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/812869#M320746</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-12T08:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: code error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/813319#M320968</link>
      <description>&lt;P&gt;Thank you for your input!&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 00:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-error/m-p/813319#M320968</guid>
      <dc:creator>jeankoutou</dc:creator>
      <dc:date>2022-05-14T00:27:18Z</dc:date>
    </item>
  </channel>
</rss>

