<?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 combine multiple if then else statements in one operation? SAS 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377078#M90528</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;is correct.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's happening is your HealthReason codes for level 3 overlap with the generic range you're using for 4. To 'override' this you can reorder the IF statements so that 3 is assigned before 4 and then the rest that meet 4 will be assigned correctly.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jul 2017 17:24:50 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-07-18T17:24:50Z</dc:date>
    <item>
      <title>How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377069#M90520</link>
      <description>&lt;P&gt;I am having a problem with a section of code; it runs fine but the frequency table that is generated is missing columns. I end up with 2 and 4 or 1 and 3 or a combination of both (I have been changing the order, etc.) New to SAS coding so hope someone can help. &amp;nbsp;I suspect I know the problem&amp;nbsp;&lt;/P&gt;&lt;P&gt;if icd9_code1&amp;lt;=&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then healthreason=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;290&lt;/STRONG&gt;&amp;lt;=icd9_code1&amp;lt;=&lt;STRONG&gt;316&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then healthreason=&lt;STRONG&gt;4&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;But do not know how to fix. I have tried everything I can think of! See full section of code below. Any help would be great!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; descriptives2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set descriptives;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*healthreason 1 is missing, 2 physical health, 3 substance use, 4 mental health;&lt;/P&gt;&lt;P&gt;healthreason=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;if icd9_code1&amp;lt;=&lt;STRONG&gt;0&lt;/STRONG&gt; then healthreason=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if &lt;STRONG&gt;290&lt;/STRONG&gt;&amp;lt;=icd9_code1&amp;lt;=&lt;STRONG&gt;316&lt;/STRONG&gt; then healthreason=&lt;STRONG&gt;4&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;if icd9_code1 in (&lt;STRONG&gt;292&lt;/STRONG&gt; &lt;STRONG&gt;303&lt;/STRONG&gt; &lt;STRONG&gt;304&lt;/STRONG&gt; &lt;STRONG&gt;305&lt;/STRONG&gt;) then healthreason=&lt;STRONG&gt;3&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else healthreason=&lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;freq&lt;/STRONG&gt; data=descriptives2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables grantyear*member_gender*healthreason;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; title 'health reason by grant year and sex';&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 16:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377069#M90520</guid>
      <dc:creator>pammers</dc:creator>
      <dc:date>2017-07-18T16:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377070#M90521</link>
      <description>&lt;P&gt;I think you missed an ELSE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if icd9_code1 &amp;lt;= 0 then healthreason=1;
ELSE IF 290 &amp;lt;= icd9_code1 &amp;lt;= 316 then healthreason = 4;
ELSE if icd9_code1 in (292 303 304 305) then healthreason = 3;
else healthreason = 2;
 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154614"&gt;@pammers&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I am having a problem with a section of code; it runs fine but the frequency table that is generated is missing columns. I end up with 2 and 4 or 1 and 3 or a combination of both (I have been changing the order, etc.) New to SAS coding so hope someone can help. &amp;nbsp;I suspect I know the problem&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if icd9_code1&amp;lt;=&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then healthreason=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;290&lt;/STRONG&gt;&amp;lt;=icd9_code1&amp;lt;=&lt;STRONG&gt;316&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then healthreason=&lt;STRONG&gt;4&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;But do not know how to fix. I have tried everything I can think of! See full section of code below. Any help would be great!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; descriptives2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set descriptives;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*healthreason 1 is missing, 2 physical health, 3 substance use, 4 mental health;&lt;/P&gt;
&lt;P&gt;healthreason=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;if icd9_code1&amp;lt;=&lt;STRONG&gt;0&lt;/STRONG&gt; then healthreason=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if &lt;STRONG&gt;290&lt;/STRONG&gt;&amp;lt;=icd9_code1&amp;lt;=&lt;STRONG&gt;316&lt;/STRONG&gt; then healthreason=&lt;STRONG&gt;4&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;if icd9_code1 in (&lt;STRONG&gt;292&lt;/STRONG&gt; &lt;STRONG&gt;303&lt;/STRONG&gt; &lt;STRONG&gt;304&lt;/STRONG&gt; &lt;STRONG&gt;305&lt;/STRONG&gt;) then healthreason=&lt;STRONG&gt;3&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else healthreason=&lt;STRONG&gt;2&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;freq&lt;/STRONG&gt; data=descriptives2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables grantyear*member_gender*healthreason;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; title 'health reason by grant year and sex';&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 16:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377070#M90521</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-18T16:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377071#M90522</link>
      <description>Thanks for the reply. I should have mentioned I tried it that (adding the&lt;BR /&gt;other else in) but it only changed the columns that showed up. It did not&lt;BR /&gt;give me all the columns.&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Tue, 18 Jul 2017 17:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377071#M90522</guid>
      <dc:creator>pammers</dc:creator>
      <dc:date>2017-07-18T17:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377072#M90523</link>
      <description>&lt;P&gt;Use the ELSE I provided and run a proc freq on the ICD codes by the Health Reason to see the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
table icdcode*healthreason / missing;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jul 2017 17:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377072#M90523</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-18T17:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377075#M90525</link>
      <description>Thank you. I will try that when I get back to the centre (where data is&lt;BR /&gt;stored).&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Tue, 18 Jul 2017 17:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377075#M90525</guid>
      <dc:creator>pammers</dc:creator>
      <dc:date>2017-07-18T17:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377076#M90526</link>
      <description>&lt;P&gt;You need to make a slight change to the code that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;suggested because, as is, health reason 3 can never get assigned:&lt;/P&gt;
&lt;PRE&gt;if icd9_code1 &amp;lt;= 0 then healthreason=1;
ELSE if icd9_code1 in (292 303 304 305) then healthreason = 3;
ELSE IF 290 &amp;lt;= icd9_code1 &amp;lt;= 316 then healthreason = 4;
else healthreason = 2;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 17:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377076#M90526</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-07-18T17:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377078#M90528</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;is correct.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's happening is your HealthReason codes for level 3 overlap with the generic range you're using for 4. To 'override' this you can reorder the IF statements so that 3 is assigned before 4 and then the rest that meet 4 will be assigned correctly.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 17:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377078#M90528</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-18T17:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple if then else statements in one operation? SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377083#M90532</link>
      <description>I think I also tried that order and so 3 displayed but not 4; may be&lt;BR /&gt;mistaken though so will re-check. Thanks!&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Tue, 18 Jul 2017 17:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-combine-multiple-if-then-else-statements-in-one/m-p/377083#M90532</guid>
      <dc:creator>pammers</dc:creator>
      <dc:date>2017-07-18T17:51:39Z</dc:date>
    </item>
  </channel>
</rss>

