<?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: Looping AND/OR statements in PROC SQL in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174745#M13409</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an option. Note that I had to modify your first "where" clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;length SQLClause $2048;&lt;BR /&gt;retain SQLClause;&lt;BR /&gt;set terms end=LastRec;&lt;BR /&gt;if _n_ = 1&lt;BR /&gt;then SQLClause = "FIND(Notes,&amp;nbsp; ' burn', 'i')&amp;gt;0 /*exclusion for valid return */ AND FIND(Notes, '"||strip(term)||"', 'i')=0";&lt;BR /&gt;else SQLClause = catx(" ", SQLClause, "AND FIND(Notes, '"||strip(term)||"', 'i')=0");&lt;BR /&gt;if LastRec then &lt;BR /&gt;call symput("SQLClause", SQLClause);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Want as&lt;BR /&gt;select * from text&lt;BR /&gt;where &amp;amp;SQLClause.;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Oct 2014 16:30:10 GMT</pubDate>
    <dc:creator>TomKari</dc:creator>
    <dc:date>2014-10-07T16:30:10Z</dc:date>
    <item>
      <title>Looping AND/OR statements in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174744#M13408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote the following hard coded CASE statment in in PROC SQL:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*Notes is the memo field */&lt;/P&gt;&lt;P&gt;MAX(CASE WHEN FIND (Notes,&amp;nbsp; ' burn', "i")&amp;gt;0 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*exclusion for valid return */&lt;BR /&gt;AND FIND(Notes, 'burner', "i")=0 &lt;BR /&gt;AND FIND(Notes, 'burn off', "i")=0&lt;BR /&gt;AND FIND(Notes, 'burnt', "i")=0&lt;BR /&gt;AND FIND(Notes, 'unit rely', "i")=0&lt;BR /&gt;AND FIND(Notes, 'burney', "i")=0&lt;BR /&gt;AND FIND(Notes, 'burnage', "i")=0&lt;BR /&gt;AND FIND(Notes, 'nnon bur', "i")=0&lt;BR /&gt;AND FIND(Notes, 'burnssd', "i")=0&lt;BR /&gt;AND FIND(Notes, 'wave', "i")=0&lt;BR /&gt;AND FIND(Notes, 'burns/', "i")=0&lt;BR /&gt;AND FIND(Notes, 'burn mark', "i")=0&lt;BR /&gt;AND Notes not like '%burn%cloth%'&lt;BR /&gt;THEN 'BURN' ELSE END)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to traslate the code to use terms stored in a table like the one below, I know it requires LOOPING of some sort, but not sure how to implement.&amp;nbsp; Thank you in advnaced&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="201" style="border: 1px solid #000000; width: 1145px; height: 65px;" width="1145"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="padding: 2px; text-align: left; color: #ffffff; background-color: #6690bc;" valign="middle"&gt;&lt;STRONG&gt;SAFETY TERM&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;EXCLUSIONS&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;SAFETY_BUCKET&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;BURN&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;N&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;BURNS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;DAMAG&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;N&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;DAMAGE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;BURNER&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Y&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;BURNS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;BURNT OFF&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Y&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;BURNS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;UNIT RELY&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Y&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;BURNS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;NONN BUR&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Y&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;BURNS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;SHOULD LOOK LIKE&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Y&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;DAMAGE&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 14:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174744#M13408</guid>
      <dc:creator>air_dedman</dc:creator>
      <dc:date>2014-10-07T14:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Looping AND/OR statements in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174745#M13409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an option. Note that I had to modify your first "where" clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;length SQLClause $2048;&lt;BR /&gt;retain SQLClause;&lt;BR /&gt;set terms end=LastRec;&lt;BR /&gt;if _n_ = 1&lt;BR /&gt;then SQLClause = "FIND(Notes,&amp;nbsp; ' burn', 'i')&amp;gt;0 /*exclusion for valid return */ AND FIND(Notes, '"||strip(term)||"', 'i')=0";&lt;BR /&gt;else SQLClause = catx(" ", SQLClause, "AND FIND(Notes, '"||strip(term)||"', 'i')=0");&lt;BR /&gt;if LastRec then &lt;BR /&gt;call symput("SQLClause", SQLClause);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Want as&lt;BR /&gt;select * from text&lt;BR /&gt;where &amp;amp;SQLClause.;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 16:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174745#M13409</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2014-10-07T16:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Looping AND/OR statements in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174746#M13410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think Tom's approach helps to generalize your match/mapping game, and maybe that's enough for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whenever I see the term "loop" with "SQL", I think "JOIN".&amp;nbsp; Because really, you want to iterate on your records that match a certain pattern and then output a new record (or set of records) that map into some new values.&amp;nbsp; If you can capture all variations of the pattern or express as a LIKE clause, then you can create a second table of those "starting values" and what they should map to, then design a JOIN to do the work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 17:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174746#M13410</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2014-10-07T17:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Looping AND/OR statements in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174747#M13411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I do plan to write a join, I will try TOM's approach. Basically I want the search to include certain string ' burn', '&amp;nbsp; scortch', ' smell', which is a series of OR or IN statements, but also exclude strings which can only be done using AND statements in SQL. I'm using SQL mostly becuase the DBA's hear wanted the code to be portable, and they only know SQL. If this is not the best approach for a SAS app, I will just tell them I have to code it in SAS. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Oct 2014 17:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Looping-AND-OR-statements-in-PROC-SQL/m-p/174747#M13411</guid>
      <dc:creator>air_dedman</dc:creator>
      <dc:date>2014-10-07T17:20:08Z</dc:date>
    </item>
  </channel>
</rss>

