<?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: SAS HELP! IF THEN STATEMENTS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883723#M349143</link>
    <description>&lt;P&gt;If everything is ending up in the first category then the value of the source variable satisfies the first IF condition.&amp;nbsp; Do you have missing values?&amp;nbsp; SAS will treat missing values are less than any actual number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To really see how your re-coding worked use PROC FREQ.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq ;
tables
   ARI_Guest_Incidence*ARI_Guest_Group_Category
   ARI_Crew_Incidence*ARI_Crew_Group_Category 
   / missing list ;
format _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Jul 2023 13:28:11 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-07-06T13:28:11Z</dc:date>
    <item>
      <title>SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883650#M349125</link>
      <description>&lt;P&gt;I am trying to create 3 groups with the code down below but SAS is only including numbers under the first group (&amp;lt;1). Why is this happening?&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;DATA WORK.IMPORT1;&lt;BR /&gt;SET WORK.IMPORT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* Calculate the group category based on incidence rate ranges */&lt;BR /&gt;IF ARI_Guest_Incidence&amp;lt;1 THEN ARI_Guest_Group_Category = "&amp;lt;1";&lt;BR /&gt;IF 1&amp;lt;=ARI_Guest_Incidence&amp;lt;=1.99 THEN ARI_Guest_Group_Category = "1-1.99";&lt;BR /&gt;IF ARI_Guest_Incidence&amp;gt;=2 THEN ARI_Guest_Group_Category = "2 and above";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;IF ARI_Crew_Incidence&amp;lt;1 THEN ARI_Crew_Group_Category = "&amp;lt;1";&lt;BR /&gt;IF 1&amp;lt;=ARI_Crew_Incidence&amp;lt;=1.99 THEN ARI_Crew_Group_Category = "1-1.99";&lt;BR /&gt;IF ARI_Crew_Incidence&amp;gt;=2 THEN ARI_Crew_Group_Category = "2 and above";&lt;BR /&gt;&lt;BR /&gt;IF CLI_Guest_Incidence&amp;lt;1 THEN CLI_Guest_Group_Category = "&amp;lt;1";&lt;BR /&gt;IF 1&amp;lt;=CLI_Guest_Incidence&amp;lt;=1.99 THEN CLI_Guest_Group_Category = "1-1.99";&lt;BR /&gt;IF CLI_Guest_Incidence&amp;gt;=2 THEN CLI_Guest_Group_Category = "2 and above";&lt;BR /&gt;&lt;BR /&gt;IF CLI_Crew_Incidence&amp;lt;1 THEN CLI_Crew_Group_Category = "&amp;lt;1";&lt;BR /&gt;IF 1&amp;lt;=CLI_Crew_Incidence&amp;lt;=1.99 THEN CLI_Crew_Group_Category = "1-1.99";&lt;BR /&gt;IF CLI_Crew_Incidence&amp;gt;=2 THEN CLI_Crew_Group_Category = "2 and above";&lt;BR /&gt;&lt;BR /&gt;IF ILI_Guest_Incidence&amp;lt;1 THEN ILI_Guest_Group_Category = "&amp;lt;1";&lt;BR /&gt;IF 1&amp;lt;=ILI_Guest_Incidence&amp;lt;=1.99 THEN ILI_Guest_Group_Category = "1-1.99";&lt;BR /&gt;IF ILI_Guest_Incidence&amp;gt;=2 THEN ILI_Guest_Group_Category = "2 and above";&lt;BR /&gt;&lt;BR /&gt;IF ILI_Crew_Incidence&amp;lt;1 THEN ILI_Crew_Group_Category = "&amp;lt;1";&lt;BR /&gt;IF 1&amp;lt;=ILI_Crew_Incidence&amp;lt;=1.99 THEN ILI_Crew_Group_Category = "1-1.99";&lt;BR /&gt;IF ILI_Crew_Incidence&amp;gt;=2 THEN ILI_Crew_Group_Category = "2 and above";&lt;BR /&gt;&lt;BR /&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 01:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883650#M349125</guid>
      <dc:creator>nmuse</dc:creator>
      <dc:date>2023-07-06T01:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883651#M349126</link>
      <description>&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After the SET statement, define the length of&amp;nbsp;&lt;SPAN&gt;ARI_Guest_Group_Category&amp;nbsp; to hold the longest value.&amp;nbsp; For example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Length&amp;nbsp;ARI_Guest_Group_Category&amp;nbsp; $&amp;nbsp; 7;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 01:25:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883651#M349126</guid>
      <dc:creator>john_mccall</dc:creator>
      <dc:date>2023-07-06T01:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883673#M349129</link>
      <description>&lt;P&gt;See Maxim 47.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a custom format with PROC FORMAT, then use this in simple assignments in PUT functions.&lt;/P&gt;
&lt;P&gt;Depending on what you intend to do with the groups, you won't even need a new variable. SAS statistical procedures (FREQ, MEANS) use formatted values automatically to build groups.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 06:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883673#M349129</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-07-06T06:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883723#M349143</link>
      <description>&lt;P&gt;If everything is ending up in the first category then the value of the source variable satisfies the first IF condition.&amp;nbsp; Do you have missing values?&amp;nbsp; SAS will treat missing values are less than any actual number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To really see how your re-coding worked use PROC FREQ.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq ;
tables
   ARI_Guest_Incidence*ARI_Guest_Group_Category
   ARI_Crew_Incidence*ARI_Crew_Group_Category 
   / missing list ;
format _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2023 13:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883723#M349143</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-06T13:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883727#M349146</link>
      <description>&lt;P&gt;The first value sets the width of the output, so it is good practice to set the output, a format or width statement will do.&amp;nbsp; A second note, and for improved efficiency, add an else to the subsequent statements so that once the category is found the remainder of the if statements do not need to be completed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have added some data to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data import;&lt;BR /&gt;format ARI_Guest_Incidence 8.3;&lt;BR /&gt;input ARI_Guest_Incidence;&lt;BR /&gt;cards;&lt;BR /&gt;1.2&lt;BR /&gt;0.1&lt;BR /&gt;3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA WORK.IMPORT1;&lt;BR /&gt;SET WORK.IMPORT;&lt;/P&gt;
&lt;P&gt;format ARI_Guest_Group_Category $15.;&lt;BR /&gt;/* Calculate the group category based on incidence rate ranges */&lt;BR /&gt;IF ARI_Guest_Incidence&amp;lt;1 THEN ARI_Guest_Group_Category = "&amp;lt;1";&lt;BR /&gt;else IF 1&amp;lt;=ARI_Guest_Incidence&amp;lt;=1.99 THEN ARI_Guest_Group_Category = "1-1.99";&lt;BR /&gt;else IF ARI_Guest_Incidence&amp;gt;=2 THEN ARI_Guest_Group_Category = "2 and above";&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 13:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/883727#M349146</guid>
      <dc:creator>DebG</dc:creator>
      <dc:date>2023-07-06T13:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884402#M349394</link>
      <description>&lt;P&gt;One last thing (that a format would address if done correctly) is that you do not address any of the values between 1.99 and 2.&lt;/P&gt;
&lt;P&gt;You have &amp;lt;=1.99 and &amp;gt;=2 as boundary values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may find that the internal numeric representation of your numbers actually occur in that gap even if you don't expect them too because of numeric precision of decimal values with binary representation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should consider learning about If then/else as well.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 22:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884402#M349394</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-07-11T22:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884450#M349419</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You may find that the internal numeric representation of your numbers actually occur in that gap even if you don't expect them to because of numeric precision of decimal values with binary representation.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Examples:&lt;/P&gt;
&lt;PRE&gt;861   data _null_;
862   a=2.3-0.3; b=0.6+0.7+0.7; c=5*0.398; d=139.3/70;
863   put (a--d) (=best32.);
864   if a&amp;lt;2 &amp;amp; b&amp;lt;2 &amp;amp; c&amp;gt;1.99 &amp;amp; d&amp;gt;1.99 then put 'Surprised?';
865   run;

a=2 b=2 c=1.99 d=1.99
Surprised?&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2023 09:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884450#M349419</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-07-12T09:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884684#M349515</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/445840"&gt;@nmuse&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You've gotten some good advice already, addressing establishment of character variable length, use of formats, and risk of uncaptured gaps in your incidence variable ranges.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would add that your code, regardless of how you choose to code the value assignment statements, would also benefit from arrays.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use two arrays, each with six elements, to reduce the size of your code, and risk of typing errors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.IMPORT1 (drop=i);
  SET WORK.IMPORT;

  array incidence{6}       ARI_Guest_Incidence       ARI_Crew_Incidence
                           CLI_Guest_Incidence       CLI_Crew_Incidence
                           ILI_Guest_Incidence       ILI_Crew_Incidence ;

  array category {6} $11   ARI_Guest_group_category  ARI_Crew_group_category
                           CLI_Guest_group_category  CLI_Crew_group_category
                           ILI_Guest_group_category  ILI_Crew_group_category ;

  do i=1 to 6;
    if incidence{i}&amp;lt;1        then category{i}="&amp;lt;1";          else
    if 1&amp;lt;=incidence{i}&amp;lt;2     then category{i}="1-1.99";      else   /*Modified per &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s comment*/
    if incidence{i}&amp;gt;=2       then category{i}="2 and above";
  end;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Jul 2023 20:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884684#M349515</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-07-13T20:49:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS HELP! IF THEN STATEMENTS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884686#M349517</link>
      <description>&lt;P&gt;To avoid the problem of values between 1.99 and 2.00 you should probably use&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    if incidence{i}&amp;lt;1 then category{i}="&amp;lt;1 or missing"; 
    else if incidence{i}&amp;lt;2 then category{i}="1-1.99"; 
    else category{i}="2 and above";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jul 2023 16:37:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-HELP-IF-THEN-STATEMENTS/m-p/884686#M349517</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-07-13T16:37:54Z</dc:date>
    </item>
  </channel>
</rss>

