<?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: where condition if using multiple datasets in proc sql join in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/where-condition-if-using-multiple-datasets-in-proc-sql-join/m-p/501854#M585</link>
    <description>&lt;P&gt;Yes, you can use case, but you have to use the right syntax.&amp;nbsp; Either:&lt;BR /&gt;case &amp;lt;expression&amp;gt; when &amp;lt;result&amp;gt; then &amp;lt;value&amp;gt; when &amp;lt;result&amp;gt; then &amp;lt;value&amp;gt; else &amp;lt;value&amp;gt; end&lt;/P&gt;
&lt;P&gt;or case when &amp;lt;expression&amp;gt; then &amp;lt;value&amp;gt;...&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;proc sql;
    create table x_01 as
	select a.*, 
		   b.TDC_RAW as DTC_A,
		   c.TDC_RAW as DTC_B,
 		 case when d.NDC_RAW ne "" then d.NDC_RAW else "" end as DC_A,
		   e.NDC_RAW as DC_B
	from rs a left join _dat b on a.ent=b.ect
	left join dat_b c on a.ent=c.ect
	left join dat d on a.ent=d.ect
	left join dat_b e on a.ent=e.ect
    
quit;&lt;/PRE&gt;
&lt;P&gt;Note, I put an alias in for ndc_raw here also, you need to be clear which ndc_raw value you are using otherwise you will get an error stating it can't decide which one.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 12:23:58 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-10-05T12:23:58Z</dc:date>
    <item>
      <title>where condition if using multiple datasets in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/where-condition-if-using-multiple-datasets-in-proc-sql-join/m-p/501852#M584</link>
      <description>&lt;P&gt;Can we use case when or where condition if we join multiple datasets using proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
    create table x_01 as
	select a.*, 
		   b.TDC_RAW as DTC_A,
		   c.TDC_RAW as DTC_B,
 		 case when NDC_RAW ne ""  d.NDC_RAW as DC_A,
		   e.NDC_RAW as DC_B
	from rs a left join _dat b on a.ent=b.ect
	left join dat_b c on a.ent=c.ect
	left join dat d on a.ent=d.ect
	left join dat_b e on a.ent=e.ect
    
quit;
&lt;/PRE&gt;
&lt;P&gt;in the above code i am using case just to filter non missing from one of the dataset but it gives error&lt;/P&gt;
&lt;P&gt;-&lt;BR /&gt; 22&lt;BR /&gt; 76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=,&lt;BR /&gt; &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;=, AND, EQ, EQT, GE, GET, GT, GTT, LE, LET, LT, LTT, NE, NET, OR,&lt;BR /&gt; THEN, ^=, |, ||, ~=.&lt;/P&gt;
&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help if we can use where/case condition while joining multiple datasets&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 12:19:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/where-condition-if-using-multiple-datasets-in-proc-sql-join/m-p/501852#M584</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-10-05T12:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: where condition if using multiple datasets in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/where-condition-if-using-multiple-datasets-in-proc-sql-join/m-p/501854#M585</link>
      <description>&lt;P&gt;Yes, you can use case, but you have to use the right syntax.&amp;nbsp; Either:&lt;BR /&gt;case &amp;lt;expression&amp;gt; when &amp;lt;result&amp;gt; then &amp;lt;value&amp;gt; when &amp;lt;result&amp;gt; then &amp;lt;value&amp;gt; else &amp;lt;value&amp;gt; end&lt;/P&gt;
&lt;P&gt;or case when &amp;lt;expression&amp;gt; then &amp;lt;value&amp;gt;...&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;proc sql;
    create table x_01 as
	select a.*, 
		   b.TDC_RAW as DTC_A,
		   c.TDC_RAW as DTC_B,
 		 case when d.NDC_RAW ne "" then d.NDC_RAW else "" end as DC_A,
		   e.NDC_RAW as DC_B
	from rs a left join _dat b on a.ent=b.ect
	left join dat_b c on a.ent=c.ect
	left join dat d on a.ent=d.ect
	left join dat_b e on a.ent=e.ect
    
quit;&lt;/PRE&gt;
&lt;P&gt;Note, I put an alias in for ndc_raw here also, you need to be clear which ndc_raw value you are using otherwise you will get an error stating it can't decide which one.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 12:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/where-condition-if-using-multiple-datasets-in-proc-sql-join/m-p/501854#M585</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-05T12:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: where condition if using multiple datasets in proc sql join</title>
      <link>https://communities.sas.com/t5/New-SAS-User/where-condition-if-using-multiple-datasets-in-proc-sql-join/m-p/501855#M586</link>
      <description>&lt;P&gt;Correct "case" code in SQL looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when d.NDC_RAW ne ""  
  then d.NDC_RAW
  else ""
end as DC_A,&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you can have multiple when-then pairs.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 12:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/where-condition-if-using-multiple-datasets-in-proc-sql-join/m-p/501855#M586</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-05T12:24:21Z</dc:date>
    </item>
  </channel>
</rss>

