<?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: how to use exists condition when querying the results from a sub-query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793413#M254306</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*ERROR: Summary functions are restricted to the SELECT and HAVING clauses only.*/
proc sql;
	create table test1 as 
	select b.*,sb.create_date as max_create_date 
	FROM game as  b  inner join (
                                select  
				                Customer_Name,Create_Date  from final 
                                group by  Customer_Name
                                having  max(Create_Date)=Create_Date
                                ) as sb
    on b.Customer_Name=sb.Customer_Name
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 31 Jan 2022 00:30:46 GMT</pubDate>
    <dc:creator>blueskyxyz</dc:creator>
    <dc:date>2022-01-31T00:30:46Z</dc:date>
    <item>
      <title>how to use exists condition when querying the results from a sub-query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793409#M254302</link>
      <description>&lt;P&gt;hi guys,&lt;/P&gt;
&lt;P&gt;can you please help me with the below query&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data final;
	format Create_Date date9.;
	input case_id $ Create_Date Customer_Name $;
	datalines;
CAS49014 22354 kelvin
CAS50201 22667 kelvin
CAS49012 22454 james
CAS49232 22337 james
;
run;

data game;
	/*format Create_Date date9.;*/
	input  Customer_Name $ game $;
	datalines;
kelvin soccer
kelvin basketball
james soccer
james basketball
;
run;&lt;/PRE&gt;
&lt;PRE&gt;proc sql;
	create table test99 as 

	select b.*,sb.max_create_date

	FROM game  b
		WHERE EXISTS (
			select max(Create_Date) as max_create_date format=date9. ,
				Customer_Name
			from work.final  
				group by sb.Customer_Name) sb 
					where  b.Customer_Name=sb.Customer_Name  )
	;
quit;
&lt;/PRE&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Error: I am getting&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="dennis_oz_0-1643585100763.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67980iEEDDCED85DFE78AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dennis_oz_0-1643585100763.png" alt="dennis_oz_0-1643585100763.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Please can you help with the above ERROR.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 23:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793409#M254302</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2022-01-30T23:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to use exists condition when querying the results from a sub-query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793412#M254305</link>
      <description>&lt;P&gt;From the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/sqlproc/p1st65qbmqdks3n1mch4yfcctexi.htm" target="_self"&gt;SQL documentation&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A multiple-value subquery can return more than one value from one column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your subquery tries to return two columns:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select max(Create_Date) as max_create_date format=date9. , Customer_Name&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can't do that.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jan 2022 00:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793412#M254305</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-31T00:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to use exists condition when querying the results from a sub-query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793413#M254306</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*ERROR: Summary functions are restricted to the SELECT and HAVING clauses only.*/
proc sql;
	create table test1 as 
	select b.*,sb.create_date as max_create_date 
	FROM game as  b  inner join (
                                select  
				                Customer_Name,Create_Date  from final 
                                group by  Customer_Name
                                having  max(Create_Date)=Create_Date
                                ) as sb
    on b.Customer_Name=sb.Customer_Name
	;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 31 Jan 2022 00:30:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793413#M254306</guid>
      <dc:creator>blueskyxyz</dc:creator>
      <dc:date>2022-01-31T00:30:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to use exists condition when querying the results from a sub-query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793414#M254307</link>
      <description>&lt;P&gt;EXISTS is just for testing whether or not any observations are found in the sub-query (hence the name).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks you want to join with the other query instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test99 as 
select b.*
     , sb.max_create_date
from game  b
left join (
  select max(Create_Date) as max_create_date format=date9. 
       , Customer_Name
  from work.final  
  group by Customer_Name
  ) sb 
on  b.Customer_Name=sb.Customer_Name  
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jan 2022 00:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-use-exists-condition-when-querying-the-results-from-a-sub/m-p/793414#M254307</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-31T00:34:04Z</dc:date>
    </item>
  </channel>
</rss>

