<?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: Query producing 0 row after having records in subquery in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910422#M359037</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp; I agree with you. But still I want to know what would be likely cause for 0 rows in the outer query? Any issue with Where clause or last group by?&lt;/P&gt;</description>
    <pubDate>Thu, 04 Jan 2024 10:35:47 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2024-01-04T10:35:47Z</dc:date>
    <item>
      <title>Query producing 0 row after having records in subquery</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910418#M359034</link>
      <description>&lt;P&gt;I'd like to understand the likely cause for 0 row after executing the aggregate query below. Subquery after first IN yields some rows but outer query is producing 0 rows. Ignore SAS syntax error please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
CREATE  TEMP TABLE TEMP_RM_DUP_MEMBER_ADDL AS
SELECT (scan(merge_key,1,"-" ))  as T_CLIENT_ID, 
                MAX(scan(merge_key,2,"-" )) as PT_MEDICARE_ID, 
                         (scan(merge_key,3,"-" )) as SUB_GROUP_POLICY_NUM, 
                          (scan(merge_key,4,"-" )) as PT_POLICY_START_DT, 
                          (scan(merge_key,5,"-" )) as PT_POLICY_END_DTFROM FORM.MEMBER_addl
WHERE ((scan(merge_key,1,"-" )), 
		(scan(merge_key,2,"-" )), 
                 (scan(merge_key,4,"-" )), 
		 (scan(merge_key,5,"-" ))) 
IN 
(
SELECT  (scan(merge_key,1,"-" )) as  PT_CLIENT_ID , 
                  MAX(scan(merge_key,3,"-" )) as SUB_GROUP_POLICY_NUM, 
                           (scan(merge_key,4,"-" )) as PT_POLICY_START_DT, 
                            (scan(merge_key,5,"-" )) as PT_POLICY_END_DT
FROM FORM.MEMBER_addl
WHERE ((scan(merge_key,1,"-" )), 
                (scan(merge_key,4,"-" )), 
		(scan(merge_key,5,"-" ))) 
IN 
(
SELECT  (scan(merge_key,1,"-" )) as  PT_CLIENT_ID, 
                  MAX(scan(merge_key,4,"-" )) as PT_POLICY_START_DT,
		          (scan(merge_key,5,"-" )) as PT_POLICY_END_DT
FROM FORM.MEMBER_addl
WHERE ((scan(merge_key,1,"-" )), 
                (scan(merge_key,5,"-" )) ) 
IN 
(
SELECT 	(scan(merge_key,1,"-" ))  as PT_CLIENT_ID, 
                 MAX(scan(merge_key,5,"-" )) as PT_POLICY_END_DT
FROM (select * from FORM.MEMBER_addl 
WHERE (scan(merge_key,1,"-" )) 
IN 
(
SELECT  MEMBER_UMI_PIN 
FROM raw.employee 
WHERE optum_correlation_id = 199341349 AND MEMBER_UMI_PIN = 17654001001 ))
GROUP BY (scan(merge_key,1,"-" )))
GROUP BY (scan(merge_key,1,"-" )), (scan(merge_key,5,"-" ))) 
GROUP BY (scan(merge_key,1,"-" )), (scan(merge_key,4,"-" )), (scan(merge_key,5,"-" ))
)
GROUP BY (scan(merge_key,1,"-" )),  (scan(merge_key,3,"-" )),                             (scan(merge_key,4,"-" )), (scan(merge_key,5,"-" ))  ;
quit;&lt;/PRE&gt;
&lt;P&gt;To summarize the issue, below query is producing 0 row in the result what would be the cause for the issue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
CREATE  TEMP TABLE TEMP_RM_DUP_MEMBER_ADDL AS
SELECT (scan(merge_key,1,"-" ))  as T_CLIENT_ID, 
                MAX(scan(merge_key,2,"-" )) as PT_MEDICARE_ID, 
                         (scan(merge_key,3,"-" )) as SUB_GROUP_POLICY_NUM, 
                         (scan(merge_key,4,"-" )) as PT_POLICY_START_DT, 
                         (scan(merge_key,5,"-" )) as PT_POLICY_END_DTFROM FORM.MEMBER_addl
WHERE ((scan(merge_key,1,"-" )), 
       (scan(merge_key,2,"-" )), 
       (scan(merge_key,4,"-" )), 
       (scan(merge_key,5,"-" ))) 
IN 
(
/*subqueries here producing results*/
)
GROUP BY (scan(merge_key,1,"-" )), (scan(merge_key,3,"-" )), (scan(merge_key,4,"-" )), (scan(merge_key,5,"-" ))  ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jan 2024 10:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910418#M359034</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2024-01-04T10:08:25Z</dc:date>
    </item>
    <item>
      <title>Re: Query producing 0 row after having records in subquery</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910420#M359035</link>
      <description>&lt;P&gt;1) Did you look int the LOG ? Usually it helps to figure out problems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Why you assume that from the fact that a sub-query returns value the main query has to return something, See example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  set sashelp.class;
  where age ne 13;
  ;
run;

proc sql; 
/* sub-query */
select age from sashelp.class where age = 13

/* query */
select * from class
where age in
(
select age from sashelp.class where age = 13
);
quit&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3) You wrote "&lt;SPAN&gt;&amp;nbsp;Ignore SAS syntax error please&lt;/SPAN&gt;" but the code is syntactically incorrect, something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;WHERE (age,sex) 
  IN 
  (select age,sex from sashelp.class where sex="F" and age in (12,13) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is "wrong code". BTW the:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;CREATE  TEMP TABLE&lt;/PRE&gt;
&lt;P&gt;is wrong too.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 10:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910420#M359035</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-01-04T10:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Query producing 0 row after having records in subquery</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910422#M359037</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp; I agree with you. But still I want to know what would be likely cause for 0 rows in the outer query? Any issue with Where clause or last group by?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 10:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910422#M359037</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2024-01-04T10:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Query producing 0 row after having records in subquery</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910432#M359039</link>
      <description>&lt;P&gt;The IN operator has the following syntax:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where A_VARIABLE in (A_LIST - from sub-query)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Query does not return anything, even when sub-query does, probably because the list of values in "A_LIST" provided by sub-query does not match with ANY value in the "A_VARIABLE" variable...&lt;/P&gt;
&lt;P&gt;1) variable="A" list is ("B" "C" "D")&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) variable="A" list is ("a" "B" "C")&lt;/P&gt;
&lt;P&gt;3) variable="&amp;nbsp; A" list is ("A "B" "C")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 11:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Query-producing-0-row-after-having-records-in-subquery/m-p/910432#M359039</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-01-04T11:19:39Z</dc:date>
    </item>
  </channel>
</rss>

