<?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: query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519676#M140805</link>
    <description>&lt;P&gt;There is no opening bracket in my code. The case has to be on the first level if the select.&lt;/P&gt;
&lt;P&gt;I suggest you invest some time and read the documentation of proc sql:&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Dec 2018 19:33:21 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-12-08T19:33:21Z</dc:date>
    <item>
      <title>query - recoding with CASE statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519639#M140787</link>
      <description>&lt;P&gt;Hey guys, hope everyone is doing great. I'm having a problem&amp;nbsp;with the following query builder step-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CASE&lt;BR /&gt;WHEN 'APPLICATION SCORE'n&amp;gt;41 THEN 'Credit_Grade'n="A"&lt;BR /&gt;WHEN ('APPLICATION SCORE'n&amp;lt;=40) AND ('APPLICATION SCORE'n&amp;gt;30) THEN 'Credit_Grade'n="B"&lt;BR /&gt;WHEN ('APPLICATION SCORE'n&amp;lt;=30) AND ('APPLICATION SCORE'n&amp;gt;20) THEN 'Credit_Grade'n="C"&lt;BR /&gt;ELSE * 'Credit_Grade'n="D" *&lt;BR /&gt;END&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help??&lt;/P&gt;</description>
      <pubDate>Sun, 09 Dec 2018 02:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519639#M140787</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-09T02:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519641#M140788</link>
      <description>&lt;P&gt;Hi and welcome to the SAS communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please be more specific about your problem. Did you try to run it? What did the log say?&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 08:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519641#M140788</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-08T08:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519642#M140789</link>
      <description>&lt;P&gt;Could you please let us know what is the error your are getting and the sample data&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 08:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519642#M140789</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-08T08:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519643#M140790</link>
      <description>&lt;P&gt;In your code Grade A values estimates from 42,43,44 and so on. The value 41 lied in Grade 'D'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;CASE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHEN colname&amp;gt;40 THEN 'Credit_Grade'n="A"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHEN colname&amp;gt;30 AND colname&amp;lt;=40) THEN 'Credit_Grade'n="B"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHEN colname&amp;gt;20 AND colname&amp;lt;=30) THEN 'Credit_Grade'n="C"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ELSE * 'Credit_Grade'n="D" *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;END&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 09:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519643#M140790</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2018-12-08T09:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519644#M140791</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when 'APPLICATION SCORE'n&amp;gt;41 then "A"
  when ('APPLICATION SCORE'n&amp;lt;=40) and ('APPLICATION SCORE'n&amp;gt;30) then "B"
  when ('APPLICATION SCORE'n&amp;lt;=30) and ('APPLICATION SCORE'n&amp;gt;20) then "C"
  else "D"
end as credit_grade&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the correct syntax of a SQL case.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 09:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519644#M140791</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-08T09:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519666#M140802</link>
      <description>&lt;P&gt;Hi Satish,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your answer, I tried running your given query command, the attached screenshot is the log I'm getting&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="problem1.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25470i9D7F49FCA3C0E324/image-size/large?v=v2&amp;amp;px=999" role="button" title="problem1.PNG" alt="problem1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please advice what to do&lt;/P&gt;&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 18:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519666#M140802</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T18:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519668#M140803</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your code. I tried running it in the query builder, and the following screenshot is my syntax errors,&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Syntax errors" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25471iF9A4F36FA45DB598/image-size/large?v=v2&amp;amp;px=999" role="button" title="problem2.PNG" alt="Syntax errors" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Syntax errors&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please advise what to do? how should I avoid such Syntax?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 18:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519668#M140803</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T18:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519670#M140804</link>
      <description>&lt;P&gt;Hi draycut,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes I have run it several times in my query builder, but getting the following Syntax errors-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="problem3.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25472i7BD4BD9D56D802C8/image-size/large?v=v2&amp;amp;px=999" role="button" title="problem3.PNG" alt="problem3.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please advise what to do?&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 18:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519670#M140804</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T18:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519676#M140805</link>
      <description>&lt;P&gt;There is no opening bracket in my code. The case has to be on the first level if the select.&lt;/P&gt;
&lt;P&gt;I suggest you invest some time and read the documentation of proc sql:&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.3&amp;amp;docsetId=sqlproc&amp;amp;docsetTarget=titlepage.htm&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 19:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519676#M140805</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-08T19:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519697#M140811</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The opening bracket is created when I'm using the Query option to create the calculated column. It closes after End AS Credi_Grade, as you can see in my screenshot. I'll try coding it in a new program to see if runs or not, will update you after. I'm also going through the documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 21:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519697#M140811</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T21:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519698#M140812</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just ran your code right now, this is the syntax error I'm getting:-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE WORK.QUERY_FOR_LOAN_PORTFOLIO AS&lt;BR /&gt;SELECT /* Credit_Grade */&lt;BR /&gt;CASE&lt;BR /&gt;WHEN 'APPLICATION SCORE'n&amp;gt;41 THEN "A"&lt;BR /&gt;WHEN ('APPLICATION SCORE'n&amp;lt;=40) AND ('APPLICATION SCORE'n&amp;gt;30) THEN "B"&lt;BR /&gt;WHEN ('APPLICATION SCORE'n&amp;lt;=30) AND ('APPLICATION SCORE'n&amp;gt;20) THEN "C"&lt;BR /&gt;ELSE * "D" * '.' END&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,&lt;BR /&gt;a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.&lt;/P&gt;&lt;P&gt;52 AS /*Credit_Grade*/&lt;BR /&gt;53 FROM WORK.LOAN_PORTFOLIO t1'.';&lt;BR /&gt;____&lt;BR /&gt;78&lt;BR /&gt;76&lt;BR /&gt;ERROR 78-322: Expecting a ','.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 22:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519698#M140812</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T22:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519700#M140814</link>
      <description>&lt;P&gt;Hi Jag,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the code and this is the sytax&amp;nbsp;error I'm getting-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;44 PROC SQL;&lt;BR /&gt;45 CREATE TABLE WORK.QUERY_FOR_LOAN_PORTFOLIO AS&lt;BR /&gt;46 SELECT /* Credit_Grade */&lt;BR /&gt;47 CASE&lt;BR /&gt;48 WHEN 'APPLICATION SCORE'n&amp;gt;41 THEN "A"&lt;BR /&gt;49 WHEN ('APPLICATION SCORE'n&amp;lt;=40) AND ('APPLICATION SCORE'n&amp;gt;30) THEN "B"&lt;BR /&gt;50 WHEN ('APPLICATION SCORE'n&amp;lt;=30) AND ('APPLICATION SCORE'n&amp;gt;20) THEN "C"&lt;BR /&gt;51 ELSE * "D" * '.' END&lt;BR /&gt;_&lt;BR /&gt;22&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,&lt;BR /&gt;a missing value, BTRIM, INPUT, PUT, SUBSTRING, USER.&lt;/P&gt;&lt;P&gt;52 AS /*Credit_Grade*/&lt;BR /&gt;53 FROM WORK.LOAN_PORTFOLIO t1'.';&lt;BR /&gt;____&lt;BR /&gt;78&lt;BR /&gt;76&lt;BR /&gt;ERROR 78-322: Expecting a ','.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 22:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519700#M140814</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T22:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519702#M140816</link>
      <description>&lt;P&gt;Please use the Insert Code and/or Insert SAS code buttons on the menu bar to paste logs and/or code TEXT into pop-up windows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;asterisk in your code is probably being read as an attempt to perform multiplication.&amp;nbsp; That operation requires two operands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why do you have them there?&lt;/P&gt;
&lt;P&gt;Also your range of values have gaps in them. A CASE statement will evaluate the conditions in order so you can simplify.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when ('application score'n&amp;gt;41) then 'A'
  when ('application score'n&amp;gt;30) then 'B'
  when ('application score'n&amp;gt;20) then 'C'
  else 'D'
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 22:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519702#M140816</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-12-08T22:55:35Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519703#M140817</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your code and here's the following syntax I'm seeing-&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
45            SELECT 'APPLICATION SCORE'n
46                     case
                       ____
                       22
                       76
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &amp;amp;, (, *, **, +, ',', -, '.', /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, 
              &amp;gt;, &amp;gt;=, ?, AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL, LE, 
              LEN, LENGTH, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

47           when ('application score'n&amp;gt;41) then 'A'
48           when ('application score'n&amp;gt;30) then 'B'
49           when ('application score'n&amp;gt;20) then 'C'
50           else 'D'
51         end
52         AS Credit_Grade
53         from Work.loan_portfolio;
54         QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Where am I going wrong?&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 23:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519703#M140817</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T23:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519709#M140819</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help, truly appreciate it! I have figured out what was wrong! You were right I was coding the wrong&amp;nbsp;way. Your code now worked for me! Thanks a bunch&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 23:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/query-recoding-with-CASE-statement/m-p/519709#M140819</guid>
      <dc:creator>Isaima0</dc:creator>
      <dc:date>2018-12-08T23:24:53Z</dc:date>
    </item>
  </channel>
</rss>

