<?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: Conditional processing with IF-THEN-ELSE  problem in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947747#M42566</link>
    <description>&lt;P&gt;Thank you...&lt;/P&gt;</description>
    <pubDate>Wed, 16 Oct 2024 19:33:04 GMT</pubDate>
    <dc:creator>heatherml20</dc:creator>
    <dc:date>2024-10-16T19:33:04Z</dc:date>
    <item>
      <title>Conditional processing with IF-THEN-ELSE  problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947699#M42561</link>
      <description>&lt;P&gt;Conditional Processing with IF-THEN/ELSE Please help me find the error:&lt;/P&gt;&lt;P&gt;Here is the question I am trying to answer and I cannot find the right code to get the "Middle" group processed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This project will use the data set sashelp.shoes.&lt;BR /&gt;Write a SAS program that will:&lt;BR /&gt;• Read sashelp.shoes as input.&lt;BR /&gt;• Create a new SAS data set, work.shoerange.&lt;BR /&gt;• Create a new character variable SalesRange that will be used to categorize the observations into&lt;BR /&gt;three groups.&lt;BR /&gt;• Set the value of SalesRange to the following:&lt;BR /&gt;o Lower when Sales are less than $100,000.&lt;BR /&gt;o Middle when Sales are between $100,000 and $200,000, inclusively.&lt;BR /&gt;o Upper when Sales are above $200,000.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I have sent through and only the lower and upper groups are calculated:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data shoerange;&lt;BR /&gt;set sashelp.shoes;&lt;BR /&gt;Length SalesRange $ 8;&lt;BR /&gt;If Sales &amp;lt; 100000.00 then&amp;nbsp; SalesRange = "Lower";&lt;BR /&gt;Else If Sales &amp;gt;=1000000.00 &amp;gt;=2000000.00 then SalesRange = "Middle";&lt;BR /&gt;Else&amp;nbsp; SalesRange = "Upper";&lt;BR /&gt;Keep Product Stores Sales SalesRange;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 16:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947699#M42561</guid>
      <dc:creator>heatherml20</dc:creator>
      <dc:date>2024-10-16T16:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional processing with IF-THEN-ELSE  problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947701#M42562</link>
      <description>Your code added a zero, so your middle range is between 1M and 2M.&lt;BR /&gt;&lt;BR /&gt;Also, you mixed the conditions around for middle. 1M will never be greater than 2M.&lt;BR /&gt;Use simple code that you understand such as:&lt;BR /&gt;and sales &amp;gt;= 200000 then</description>
      <pubDate>Wed, 16 Oct 2024 16:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947701#M42562</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2024-10-16T16:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional processing with IF-THEN-ELSE  problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947704#M42563</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/397947"&gt;@heatherml20&lt;/a&gt;, a couple of notes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. There are extra 0's in the ELSE IF/THEN statement range for the Middle group. I recommend writing out large values with the comma separating every three digits (100,000) and then going through and removing the commas (100000) to ensure you're always capturing the right value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. The range for Sales has to be specified as a mathematical range in one condition ( a &amp;lt;= Sales &amp;lt;= b ) or as separate conditions combined with AND (Sales &amp;gt;= a AND Sales &amp;lt;= b).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. No decimal places required here since we're capturing all values with integers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data shoerange;
	set sashelp.shoes;
	Length SalesRange $ 8;
	
	If Sales &amp;lt; 100000 then  SalesRange = "Lower";
	Else If  100000 &amp;lt;= Sales &amp;lt;=200000 then SalesRange = "Middle";
	Else  SalesRange = "Upper";

	Keep Product Stores Sales SalesRange;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 16:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947704#M42563</guid>
      <dc:creator>antonbcristina</dc:creator>
      <dc:date>2024-10-16T16:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional processing with IF-THEN-ELSE  problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947717#M42564</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/397947"&gt;@heatherml20&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You can also simplify the range condition by omitting the lower bound: The inequality&amp;nbsp;&lt;FONT face="courier new,courier"&gt;100000 &amp;lt;= Sales&lt;/FONT&gt; is already implied by the ELSE keyword in conjunction with the previous IF condition&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Sales &amp;lt; 100000&lt;/FONT&gt;.&lt;/LI&gt;
&lt;LI&gt;Using scientific notation (e.g.,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;100000=1e5&lt;/FONT&gt;) you could avoid typing many zeros.&lt;/LI&gt;
&lt;LI&gt;Note that missing values in variable &lt;FONT face="courier new,courier"&gt;Sales&lt;/FONT&gt;&amp;nbsp;(which do not occur in&amp;nbsp;SASHELP.SHOES) would satisfy the condition &lt;FONT face="courier new,courier"&gt;Sales &amp;lt; 100000&lt;/FONT&gt;, but should possibly not be classified as "Lower." So, for a real-world dataset the IF-THEN/ELSE statement could look like this:&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(Sales) then SalesRange = "Missing";
else if Sales &amp;lt; 1e5 then SalesRange = "Lower";
else if Sales &amp;lt;=2e5 then SalesRange = "Middle";
else SalesRange = "Upper";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;See the 2018 post "&lt;A href="https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517857/highlight/true#M140082" target="_blank" rel="noopener"&gt;Re: If then statement&lt;/A&gt;" for yet another approach.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 17:26:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947717#M42564</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-10-16T17:26:52Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional processing with IF-THEN-ELSE  problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947746#M42565</link>
      <description>&lt;P&gt;Thank you ...I did figure out to put separate statements for the Middle category but I was looking for what you have shown me that works better!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 19:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947746#M42565</guid>
      <dc:creator>heatherml20</dc:creator>
      <dc:date>2024-10-16T19:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional processing with IF-THEN-ELSE  problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947747#M42566</link>
      <description>&lt;P&gt;Thank you...&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 19:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-processing-with-IF-THEN-ELSE-problem/m-p/947747#M42566</guid>
      <dc:creator>heatherml20</dc:creator>
      <dc:date>2024-10-16T19:33:04Z</dc:date>
    </item>
  </channel>
</rss>

