<?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: If/ Else statement error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280450#M56674</link>
    <description>&lt;P&gt;You also shouldn't calculate age with that formula. If you search on here the question of how to calculate age has come up a few times in the last few weeks and you'll find several formulas to calculate age.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Jun 2016 15:15:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-06-27T15:15:47Z</dc:date>
    <item>
      <title>If/ Else statement error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280446#M56671</link>
      <description>&lt;P&gt;Can anyone provide some help with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data age;&lt;BR /&gt;set models_baseline;&lt;BR /&gt;age= Int((survey_compdate-dob)/365.25);&lt;BR /&gt;if age = "0" then delete;&lt;BR /&gt;else if age &amp;gt;= "18" and &amp;lt;= "35" then agegroup=1;&lt;BR /&gt;else if age &amp;gt;= "36" and &amp;lt;= "44" then agegroup=2;&lt;BR /&gt;else if age &amp;gt;= "45" and &amp;lt;= "59" then agegroup=3;&lt;BR /&gt;else if age &amp;gt;= "60" then agegroup=4;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am receiving the following error messages in the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;7237 data age;&lt;BR /&gt;7238 set models_baseline;&lt;BR /&gt;7239 age= Int((survey_compdate-dob)/365.25);&lt;BR /&gt;7240 if age = "0" then delete;&lt;BR /&gt;7241 else if age &amp;gt;= "18" and &amp;lt;= "35" then agegroup=1;&lt;BR /&gt;-- ---------&lt;BR /&gt;22 180 180&lt;BR /&gt;7242 else if age &amp;gt;= "36" and &amp;lt;= "44" then agegroup=2;&lt;BR /&gt;-- ---------&lt;BR /&gt;22 180 180&lt;BR /&gt;7243 else if age &amp;gt;= "45" and &amp;lt;= "59" then agegroup=3;&lt;BR /&gt;-- ---------&lt;BR /&gt;22 180 180&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,&lt;BR /&gt;a numeric constant, a datetime constant, a missing value, INPUT, PUT.&lt;/P&gt;&lt;P&gt;ERROR 180-322: Statement is not valid or it is used out of proper order.&lt;/P&gt;&lt;P&gt;7244 else if age &amp;gt;= "60" then agegroup=4;&lt;BR /&gt;7245 run;&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by:&lt;BR /&gt;(Line):(Column).&lt;BR /&gt;7240:10 7241:16 7242:16 7243:16 7244:16&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.AGE may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 148 variables.&lt;BR /&gt;WARNING: Data set WORK.AGE was not replaced because this step was stopped.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 15:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280446#M56671</guid>
      <dc:creator>malikah_sph</dc:creator>
      <dc:date>2016-06-27T15:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: If/ Else statement error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280448#M56673</link>
      <description>&lt;P&gt;You've specified your else statements incorrectly. Also character values for age won't compare accuratkey, 9 is greater than 10 alphabetically. Make sure you have a numeric variable. That's probably why you have the note regarding type conversion in your log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Heres an example of how it should look:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else if age &amp;gt;= 45 and AGE &amp;lt;= 59 then agegroup=3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;else if 45 &amp;lt;= age &amp;lt;= 59 then agegroup=3;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 15:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280448#M56673</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-27T15:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: If/ Else statement error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280450#M56674</link>
      <description>&lt;P&gt;You also shouldn't calculate age with that formula. If you search on here the question of how to calculate age has come up a few times in the last few weeks and you'll find several formulas to calculate age.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 15:15:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280450#M56674</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-27T15:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: If/ Else statement error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280451#M56675</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your response. I initially did it the way you mentioned it above and I remember receiving an error when I did it that way as well. However, I will try it again.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 15:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280451#M56675</guid>
      <dc:creator>malikah_sph</dc:creator>
      <dc:date>2016-06-27T15:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: If/ Else statement error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280454#M56677</link>
      <description>Is there a reason why, its not an acceptable formula. I previously tried several other formulas and the one that I used is the only one that provided me success.</description>
      <pubDate>Mon, 27 Jun 2016 15:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280454#M56677</guid>
      <dc:creator>malikah_sph</dc:creator>
      <dc:date>2016-06-27T15:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: If/ Else statement error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280462#M56681</link>
      <description>&lt;P&gt;The IF condition? Your missing a variable to compare - it isn't valid SAS syntax.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sue what worked so can't comment beyond that without seeing the code. Part of the problem likely stems from the fact that there's more than one thing wrong with the code so without fixing all the errors you can get unexpected results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 15:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280462#M56681</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-27T15:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: If/ Else statement error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280467#M56683</link>
      <description>I was able to get everything to work using the age calculation and your suggestions for the age group. I see where I made my error.&lt;BR /&gt;&lt;BR /&gt;Thank you</description>
      <pubDate>Mon, 27 Jun 2016 15:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-Else-statement-error/m-p/280467#M56683</guid>
      <dc:creator>malikah_sph</dc:creator>
      <dc:date>2016-06-27T15:59:39Z</dc:date>
    </item>
  </channel>
</rss>

