<?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 How To Use If Statement in a Join in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-To-Use-If-Statement-in-a-Join/m-p/795248#M255053</link>
    <description>&lt;P&gt;Im looking to put an IF Statement in my join, here is the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE WORK.WANT AS
		SELECT  t1.*,
			    t2.Group
		FROM WORK.HAVE t1 INNER JOIN
			 WORK.GROUPS t2 ON (t1.UNIQ_ID = t2.UNIQ_ID AND t1.TYPE = t2.TYPE AND
					t2.PERIOD = IF(t1.TYPE = 'ABC', SUBSTR(t1.DATE_SK, 1, 6), SUBSTR(t1.DATE_SK, 1, 4)01));
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I keep getting the following error:&lt;/P&gt;
&lt;PRE&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, CONTAINS, 
              EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  &lt;/PRE&gt;
&lt;P&gt;Any thoughts? Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 09 Feb 2022 17:50:27 GMT</pubDate>
    <dc:creator>mhoward2</dc:creator>
    <dc:date>2022-02-09T17:50:27Z</dc:date>
    <item>
      <title>How To Use If Statement in a Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-Use-If-Statement-in-a-Join/m-p/795248#M255053</link>
      <description>&lt;P&gt;Im looking to put an IF Statement in my join, here is the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE WORK.WANT AS
		SELECT  t1.*,
			    t2.Group
		FROM WORK.HAVE t1 INNER JOIN
			 WORK.GROUPS t2 ON (t1.UNIQ_ID = t2.UNIQ_ID AND t1.TYPE = t2.TYPE AND
					t2.PERIOD = IF(t1.TYPE = 'ABC', SUBSTR(t1.DATE_SK, 1, 6), SUBSTR(t1.DATE_SK, 1, 4)01));
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I keep getting the following error:&lt;/P&gt;
&lt;PRE&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, CONTAINS, 
              EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  &lt;/PRE&gt;
&lt;P&gt;Any thoughts? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 17:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-Use-If-Statement-in-a-Join/m-p/795248#M255053</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2022-02-09T17:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How To Use If Statement in a Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-Use-If-Statement-in-a-Join/m-p/795253#M255057</link>
      <description>&lt;P&gt;There is no IF() function of that nature in SAS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are IFC()/IFN() functions and you can use those or use a CASE statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that 01 beside the substring will also cause an issue?&lt;/P&gt;
&lt;P&gt;Did you mean to add a CATT function to concatenate the '01' value to the substring value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
	CREATE TABLE WORK.WANT AS
		SELECT  t1.*,
			    t2.Group
		FROM WORK.HAVE t1 INNER JOIN
			 WORK.GROUPS t2 ON (t1.UNIQ_ID = t2.UNIQ_ID AND t1.TYPE = t2.TYPE AND
					t2.PERIOD = IF(t1.TYPE = 'ABC', SUBSTR(t1.DATE_SK, 1, 6), &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;SUBSTR(t1.DATE_SK, 1, 4)01&lt;/STRONG&gt;&lt;/FONT&gt;));
QUIT;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/279427"&gt;@mhoward2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Im looking to put an IF Statement in my join, here is the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	CREATE TABLE WORK.WANT AS
		SELECT  t1.*,
			    t2.Group
		FROM WORK.HAVE t1 INNER JOIN
			 WORK.GROUPS t2 ON (t1.UNIQ_ID = t2.UNIQ_ID AND t1.TYPE = t2.TYPE AND
					t2.PERIOD = IF(t1.TYPE = 'ABC', SUBSTR(t1.DATE_SK, 1, 6), SUBSTR(t1.DATE_SK, 1, 4)01));
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I keep getting the following error:&lt;/P&gt;
&lt;PRE&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, ?, AND, CONTAINS, 
              EQ, EQT, GE, GET, GT, GTT, LE, LET, LIKE, LT, LTT, NE, NET, OR, ^=, |, ||, ~=.  &lt;/PRE&gt;
&lt;P&gt;Any thoughts? Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Feb 2022 17:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-Use-If-Statement-in-a-Join/m-p/795253#M255057</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-02-09T17:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: How To Use If Statement in a Join</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-To-Use-If-Statement-in-a-Join/m-p/795257#M255059</link>
      <description>Those two pieces solved it, thank you so much! Clearly I need to learn how to use functions in SAS better!</description>
      <pubDate>Wed, 09 Feb 2022 18:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-To-Use-If-Statement-in-a-Join/m-p/795257#M255059</guid>
      <dc:creator>mhoward2</dc:creator>
      <dc:date>2022-02-09T18:04:02Z</dc:date>
    </item>
  </channel>
</rss>

