<?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 Proper SQL query.. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24008#M5391</link>
    <description>Hello all-&lt;BR /&gt;
I have a Proc SQL that goes like this (truncated to the problem part.)&lt;BR /&gt;
&lt;BR /&gt;
To explain-the format $Special gives either a 'BMT' or 'ONC' designation.&lt;BR /&gt;
What I am attempting to do is make a case in that when it does not match those two parameters it goes to another table and grabs the designaton from there. I have tried difference variances such as call the format and then try to override when blank, but that doesn't seem to work either..&lt;BR /&gt;
Any advice would be helpful. &lt;BR /&gt;
&lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Lawrence&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table L7 as Case when PUT(A.Attending_Physician, $Special.) ne ('BMT'||'ONC')&lt;BR /&gt;
 then C.Svce else  PUT(A.Attending_Physician, $Special.) end as SVC&lt;BR /&gt;
FROM ACUTE7L as A LEFT JOIN GOLDSBY as C on A.VISIT=C.VISIT; &lt;BR /&gt;
QUIT;</description>
    <pubDate>Tue, 08 Mar 2011 00:02:15 GMT</pubDate>
    <dc:creator>_LB</dc:creator>
    <dc:date>2011-03-08T00:02:15Z</dc:date>
    <item>
      <title>Proper SQL query..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24008#M5391</link>
      <description>Hello all-&lt;BR /&gt;
I have a Proc SQL that goes like this (truncated to the problem part.)&lt;BR /&gt;
&lt;BR /&gt;
To explain-the format $Special gives either a 'BMT' or 'ONC' designation.&lt;BR /&gt;
What I am attempting to do is make a case in that when it does not match those two parameters it goes to another table and grabs the designaton from there. I have tried difference variances such as call the format and then try to override when blank, but that doesn't seem to work either..&lt;BR /&gt;
Any advice would be helpful. &lt;BR /&gt;
&lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Lawrence&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table L7 as Case when PUT(A.Attending_Physician, $Special.) ne ('BMT'||'ONC')&lt;BR /&gt;
 then C.Svce else  PUT(A.Attending_Physician, $Special.) end as SVC&lt;BR /&gt;
FROM ACUTE7L as A LEFT JOIN GOLDSBY as C on A.VISIT=C.VISIT; &lt;BR /&gt;
QUIT;</description>
      <pubDate>Tue, 08 Mar 2011 00:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24008#M5391</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-03-08T00:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proper SQL query..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24009#M5392</link>
      <description>I think that you have to do this with two queries.&lt;BR /&gt;
&lt;BR /&gt;
The CASE statement is a mixture of SQL and DATA step logic (CASE clauses are OK, THEN and ELSE are not).  Lastly, the PUT (..) NE ('BMT'||'ONC') won't work because you are both mixed syntax and are using a concatenation operator.&lt;BR /&gt;
&lt;BR /&gt;
Create a table for the BMT and ONC folk and then one for the others.  Finally combine the two using the UNION operator in SQL..</description>
      <pubDate>Tue, 08 Mar 2011 02:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24009#M5392</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2011-03-08T02:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proper SQL query..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24010#M5393</link>
      <description>In your query, the case expression needs to be part of a select clause.  Try adding the word SELECT before the word CASE in your proc sql step.  I don't understand what PUT(A.Attending_Physician, $Special.) ne ('BMT'||'ONC') is suppose to do.  Based on your description, I think that you might want to use PUT(A.Attending_Physician, $Special.) not in ('BMT' 'ONC') .</description>
      <pubDate>Tue, 08 Mar 2011 13:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24010#M5393</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-03-08T13:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Proper SQL query..</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24011#M5394</link>
      <description>Thanks for the help, Polingjw's query worked best. &lt;BR /&gt;
The PUT(A.Attending_Physician, $Special.)  simply assigns a format that I created. Just my SQL could use some work.&lt;BR /&gt;
&lt;BR /&gt;
Thank you.&lt;BR /&gt;
&lt;BR /&gt;
Lawrence</description>
      <pubDate>Tue, 08 Mar 2011 16:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proper-SQL-query/m-p/24011#M5394</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-03-08T16:00:48Z</dc:date>
    </item>
  </channel>
</rss>

