<?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: Proc SQL - IF/THEN Conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298429#M62761</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;Is that really so?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if I had this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data person;
   input name $ dept $;
   datalines;
John Sales
Mary Acctng&lt;BR /&gt;Mark Marketing&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then I did a set of CASE/THEN statements (within a PROC SQL somewhere):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CASE&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN name='John' and dept='Sales' THEN 'John from Sales'&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN name='Mary' and dept='Acctng' THEN 'Mary from Accounting'&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN name='Mark' and dept='Marketing' THEN 'Mark from Marketing'&lt;/P&gt;&lt;P&gt;END AS People,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It doesn't exit the CASES after the first WHEN (which is a condition that is met). Explain this.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Sep 2016 20:01:47 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2016-09-14T20:01:47Z</dc:date>
    <item>
      <title>Proc SQL - IF/THEN Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298394#M62752</link>
      <description>&lt;P&gt;Hi. Is there anyway to translate this type of IF/THEN data step coding into Proc SQL coding? &amp;nbsp;Essentially I need to test a series of rule conditions and if a rule is true then I need to set the analysis_desc and rule_order variables to specific values. The tricky part is that once a rule condition is met for a record then no other rule conditions should be tested for that record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;     if (A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL ) THEN 
		do;
			analysis_desc=trim("ACTUAL DELIVERY DATE MISSING IN IV ");
			rule_order=1.0;
		end;
	 ELSE IF (A.ACTUAL_DLVRY_DATE &amp;gt; B.ACTUAL_DLVRY_DATE ) THEN 
		do;
			analysis_desc=trim("ACTUAL DELIVERY DATE LATER IN IV ");
			rule_order=1.0;
		end;
     ELSE do;
		analysis_desc='';
		rule_order=.;
	 END;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I had been trying to use Case statements, but found I couldn't figure out a way to stop the code after the first rule condtion was true.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    CASE
           WHEN (A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL ) THEN "ACTUAL DELIVERY DATE MISSING IN IV"
           WHEN (A.ACTUAL_DLVRY_DATE &amp;gt; B.ACTUAL_DLVRY_DATE ) THEN "ACTUAL DELIVERY DATE LATER IN IV"
     ELSE ''
     END as Analysis_Desc,
     CASE
           WHEN A.ACTUAL_DLVRY_DATE IS NULL AND B.ACTUAL_DLVRY_DATE IS NOT NULL THEN 1.0
           WHEN A.ACTUAL_DLVRY_DATE &amp;gt; B.ACTUAL_DLVRY_DATE THEN 1.5
     ELSE .
     END as Rule_Order&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need to use Proc SQL in this case because the rule condtions are provided to us as Oracle SQL Where conditions and must be integrated into my SAS program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd really appreciate any ideas for accomplishing this type of functionality in my SAS program.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 18:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298394#M62752</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2016-09-14T18:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - IF/THEN Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298398#M62756</link>
      <description>&lt;P&gt;That's how CASE/WHEN statements work. They end if one condition is met. P&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code as written should work. Please explain how it's not with a data example.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 18:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298398#M62756</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-14T18:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - IF/THEN Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298429#M62761</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;Is that really so?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What if I had this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data person;
   input name $ dept $;
   datalines;
John Sales
Mary Acctng&lt;BR /&gt;Mark Marketing&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then I did a set of CASE/THEN statements (within a PROC SQL somewhere):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CASE&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN name='John' and dept='Sales' THEN 'John from Sales'&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN name='Mary' and dept='Acctng' THEN 'Mary from Accounting'&lt;/P&gt;&lt;P&gt;&amp;nbsp; WHEN name='Mark' and dept='Marketing' THEN 'Mark from Marketing'&lt;/P&gt;&lt;P&gt;END AS People,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It doesn't exit the CASES after the first WHEN (which is a condition that is met). Explain this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 20:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298429#M62761</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-09-14T20:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - IF/THEN Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298441#M62765</link>
      <description>&lt;P&gt;I think you're misunderstanding how the Case statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Case-When operates on each line of the data set&lt;/STRONG&gt;&lt;/U&gt;. Once a condition is met for that line it stop and then proceeds to the next line of the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It sounds like you might want a set operation? So once some condition is met, it stops processing all further rows of data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What would you expect to happen?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The results are following:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Obs name dept People 
1 John Sales John from Sales 
2 Mary Acctng Mary from Accounting 
3 Mark Marketing Mark from Marketing 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Sep 2016 20:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298441#M62765</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-14T20:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL - IF/THEN Conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298451#M62770</link>
      <description>&lt;P&gt;Ahh I see. This makes a lot more sense now. I was under the impression that if one line from the data met the condition it will exit from the data, but now I see that it continues to iterate through the datalines to see if the same condition is met. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Sep 2016 21:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-SQL-IF-THEN-Conditions/m-p/298451#M62770</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-09-14T21:39:56Z</dc:date>
    </item>
  </channel>
</rss>

