<?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: 2 Tips related to COMMAS and CASE expressions in PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652703#M195997</link>
    <description>&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I mean is, if you forget to put a comma in where you should, you will get an error message, and if you put in an extra comma in where you shouldn't, you will get an error message. In either case, your code won't run. Consider the following 3 examples that would lead to errors in the code below:&lt;/P&gt;&lt;P&gt;1) missing the comma after &lt;STRONG&gt;select colic.*&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2) missing the comma after &lt;STRONG&gt;end as i1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;3) having an extra (unwarranted) comma after &lt;STRONG&gt;end as i2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;proc sql; 
create table coloid as   
select colic.* , 
		case 
			when IND=1 then 1
			else 0
		end as i1,
		case 
			when IND=2 then 1
			else 0
		end as i2
from colic
where LEV&amp;lt;=0.999
order by colic.cusip, colic.fyear;
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jun 2020 21:13:17 GMT</pubDate>
    <dc:creator>jjsingh04</dc:creator>
    <dc:date>2020-06-03T21:13:17Z</dc:date>
    <item>
      <title>2 Tips related to COMMAS and CASE expressions in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652696#M195993</link>
      <description>&lt;P&gt;Hi everyone. This isn't a question but a couple of tips.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In PROC SQL, remember that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) a) If you use a CASE expression, you MUST put a COMMA at the end of the SELECT statement that PRECEDES the CASE expression.&lt;/P&gt;&lt;P&gt;b) However, if you DON'T use a CASE expression, you MUST NOT put a COMMA at the end of your SELECT statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) a) When a CASE expression is followed by another CASE expression, you MUST put a COMMA at the end of the 1st CASE expression.&lt;BR /&gt;b) But if a CASE expression is NOT followed by another CASE expression, you MUST NOT put a COMMA at the end of it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;See the code below for examples.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
create table coloid as   
select colic.* , 
		case 
			when IND=1 then 1
			else 0
		end as i1,
		case 
			when IND=2 then 1
			else 0
		end as i2
from colic
where LEV&amp;lt;=0.999
order by colic.cusip, colic.fyear;
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 21:10:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652696#M195993</guid>
      <dc:creator>jjsingh04</dc:creator>
      <dc:date>2020-06-03T21:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Tips related to COMMAS and CASE statements in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652701#M195996</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/327936"&gt;@jjsingh04&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;?? Your statements don't make sense to me.&lt;/P&gt;
&lt;P&gt;You just have a comma separated list in the Select statement where an element can be just a column name or an expression. There is nothing special about the CASE statement.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 23:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652701#M195996</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-02T23:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Tips related to COMMAS and CASE expressions in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652703#M195997</link>
      <description>&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I mean is, if you forget to put a comma in where you should, you will get an error message, and if you put in an extra comma in where you shouldn't, you will get an error message. In either case, your code won't run. Consider the following 3 examples that would lead to errors in the code below:&lt;/P&gt;&lt;P&gt;1) missing the comma after &lt;STRONG&gt;select colic.*&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2) missing the comma after &lt;STRONG&gt;end as i1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;3) having an extra (unwarranted) comma after &lt;STRONG&gt;end as i2&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;proc sql; 
create table coloid as   
select colic.* , 
		case 
			when IND=1 then 1
			else 0
		end as i1,
		case 
			when IND=2 then 1
			else 0
		end as i2
from colic
where LEV&amp;lt;=0.999
order by colic.cusip, colic.fyear;
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 21:13:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652703#M195997</guid>
      <dc:creator>jjsingh04</dc:creator>
      <dc:date>2020-06-03T21:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Tips related to COMMAS and CASE statements in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652719#M196005</link>
      <description>&lt;P&gt;There should be a comma between each element listed after the select keyword, used as a separator.&lt;/P&gt;
&lt;P&gt;Whether this element is derived from a variable name, a calculation, a function, a case statement, or a combination of these, makes no difference.&lt;/P&gt;
&lt;P&gt;The rule is simply: There must a comma &lt;EM&gt;between&lt;/EM&gt; each query element listed after the select keyword, to separate them. Not before. Not after. Between.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I fail to see why you consider &lt;EM&gt;case&lt;/EM&gt; to be special.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 02:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652719#M196005</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-03T02:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Tips related to COMMAS and CASE expressions in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652738#M196011</link>
      <description>&lt;P&gt;Chris,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I take it from what you and Patrick have written that there are some generalities for SELECT's syntax that I'm not as familiar with. I'm just trying to help people who are new to using the CASE expression in overcoming the coding problems with commas that I've had to deal with in the past. I'm not trying to imply that CASE expressions are necessarily unique in their construct; I've just found them to be particularly problematic for new coders.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;J.J.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 21:12:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652738#M196011</guid>
      <dc:creator>jjsingh04</dc:creator>
      <dc:date>2020-06-03T21:12:18Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Tips related to COMMAS and CASE statements in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652759#M196019</link>
      <description>&lt;P&gt;The CASE thing is not a "statement", it is an SQL element, and is part of your SELECT statement, which has a list of comma-separated columns (with "*" denoting all columns from the input).&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 05:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652759#M196019</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-03T05:37:47Z</dc:date>
    </item>
    <item>
      <title>Re: 2 Tips related to COMMAS and CASE expressions in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652997#M196108</link>
      <description>&lt;P&gt;That's interesting. Thanks for the info.&lt;/P&gt;&lt;P&gt;J.J.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jun 2020 22:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-Tips-related-to-COMMAS-and-CASE-expressions-in-PROC-SQL/m-p/652997#M196108</guid>
      <dc:creator>jjsingh04</dc:creator>
      <dc:date>2020-06-03T22:02:39Z</dc:date>
    </item>
  </channel>
</rss>

