<?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: Case statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280837#M56823</link>
    <description>&lt;P&gt;SQL provides you with much more flexibility than Excel formulas. Once you master SQL basics, you will not want to go back. I suspect that you would want to do a lot more in a single query :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test1.new as
select 
	*, 
	case 
		when accountNb in (select accountNb from table2) then "YES"
		else "NO" end as inTable2
from table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2016 16:43:55 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-06-28T16:43:55Z</dc:date>
    <item>
      <title>Case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280832#M56822</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im familiar to do an IF statement in Excel but not in SAS ( yet)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im using proc sql and want to create a new table with the results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two tables and want to create a third one that says if the account number matches from table 1 with table 2 then add an another column in table 1 and say YES otherwise no.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finish this...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create table test1.new &amp;nbsp;as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select A.* (table1)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;----case statement--- ( if account number column matches from table 1) then create new column and say YEs otherwise No,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 15:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280832#M56822</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-28T15:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280837#M56823</link>
      <description>&lt;P&gt;SQL provides you with much more flexibility than Excel formulas. Once you master SQL basics, you will not want to go back. I suspect that you would want to do a lot more in a single query :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test1.new as
select 
	*, 
	case 
		when accountNb in (select accountNb from table2) then "YES"
		else "NO" end as inTable2
from table1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 16:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280837#M56823</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-28T16:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: Case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280838#M56824</link>
      <description>&lt;P&gt;Why not learn SAS instead of SQL?&lt;/P&gt;
&lt;P&gt;To combine two tables use the MERGE statement. &amp;nbsp;If you have other variables in TABLE2 that you do not want to carry over into the new table then use a KEEP= or DROP= dataset option. &amp;nbsp;Personally I find it easier to use&amp;nbsp;1/0 numeric variables than 'YES'/'NO' character variables. &amp;nbsp;Below is code to make both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
   merge table1 (in=in1) table2(in=in2 keep=id);
   by id;
   if in1;
   new_numeric=in2;
   if in2 then new_character='YES';
   else new_character='NO ';
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 16:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280838#M56824</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-06-28T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280844#M56826</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Why not learn SAS instead of SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because only SAS understands SAS?&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Seriously: if you are going invest in SAS, learn both! You'll need both to tackle DS2 later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 17:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280844#M56826</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-28T17:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280846#M56827</link>
      <description>&lt;P&gt;Thank you but I get a Syntax Error&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table test.intscrub as&lt;BR /&gt;select A.*, case when A.account_number in (select B.Acc_Num from test.scrub B) then "YES" else "No" end as &lt;SPAN&gt;test&lt;/SPAN&gt;&lt;SPAN&gt;.scrub&lt;/SPAN&gt; B&lt;BR /&gt;from &lt;SPAN&gt;test&lt;/SPAN&gt;&lt;SPAN&gt;.intscrub&lt;/SPAN&gt; A&lt;BR /&gt;;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;any suggestions?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 17:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280846#M56827</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-28T17:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280848#M56829</link>
      <description>&lt;P&gt;It makes no sense to say "&lt;SPAN&gt;as &lt;/SPAN&gt;&lt;SPAN&gt;test&lt;/SPAN&gt;&lt;SPAN&gt;.scrub&lt;/SPAN&gt;&lt;SPAN&gt; B".&amp;nbsp;&lt;/SPAN&gt;Get rid of the A's and B's in your query, they aren't needed. Read about aliases&amp;nbsp;in the SAS/SQL doc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test.intscrub_1 as
select *, case when account_number in (select Acc_Num from test.scrub) then "YES" else "No" end as scrub
from test.intscrub;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do not overwrite your input table until you have fully validated your query.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2016 17:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Case-statement/m-p/280848#M56829</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-28T17:23:31Z</dc:date>
    </item>
  </channel>
</rss>

