<?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: proc sql : error in table creation in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70485#M20287</link>
    <description>Hi.&lt;BR /&gt;
you need a 'having' statement to fliter the group.&lt;BR /&gt;
try this.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data patrick;&lt;BR /&gt;
 input id $ product;&lt;BR /&gt;
datalines;&lt;BR /&gt;
101 6&lt;BR /&gt;
101 3&lt;BR /&gt;
101 5&lt;BR /&gt;
101 3&lt;BR /&gt;
102 2&lt;BR /&gt;
102 3&lt;BR /&gt;
102 6&lt;BR /&gt;
102 6&lt;BR /&gt;
103 6&lt;BR /&gt;
103 6&lt;BR /&gt;
103 6&lt;BR /&gt;
103 6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as&lt;BR /&gt;
  select *&lt;BR /&gt;
    from patrick&lt;BR /&gt;
      where product in (6 3)&lt;BR /&gt;
        group by id&lt;BR /&gt;
          having count( distinct product) ge 2;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
    <pubDate>Wed, 08 Sep 2010 05:24:07 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2010-09-08T05:24:07Z</dc:date>
    <item>
      <title>proc sql : error in table creation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70481#M20283</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I have a data set "test" from which I want to select only those observations for which the product column is 6 AND 3 for every group of ID. The desired output table is test1 below.&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;&lt;B&gt;test&lt;/B&gt;&lt;/U&gt;&lt;BR /&gt;
	&lt;BR /&gt;
ID	product&lt;BR /&gt;
-----------------------&lt;BR /&gt;
101	6&lt;BR /&gt;
101	3&lt;BR /&gt;
101	5&lt;BR /&gt;
101	3&lt;BR /&gt;
-----------------------&lt;BR /&gt;
102	2&lt;BR /&gt;
102	3&lt;BR /&gt;
102	6&lt;BR /&gt;
102	6&lt;BR /&gt;
-----------------------&lt;BR /&gt;
103	6&lt;BR /&gt;
103	6&lt;BR /&gt;
103	6&lt;BR /&gt;
103	6&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;U&gt;test1	&lt;/U&gt;&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
ID	product&lt;BR /&gt;
----------------------&lt;BR /&gt;
101	6&lt;BR /&gt;
101	3&lt;BR /&gt;
101	3&lt;BR /&gt;
----------------------&lt;BR /&gt;
102	3&lt;BR /&gt;
102	6&lt;BR /&gt;
102	6&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;&lt;/B&gt;&lt;U&gt;&lt;/U&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I tried using the following program but it fails to group by the IDs and is returning any observation that is a 6 or a 3. Can anybody please point what's wrong?&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as&lt;BR /&gt;
select *&lt;BR /&gt;
from test&lt;BR /&gt;
where product in (6 3)&lt;BR /&gt;
group by hhid;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Tue, 07 Sep 2010 15:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70481#M20283</guid>
      <dc:creator>spg</dc:creator>
      <dc:date>2010-09-07T15:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql : error in table creation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70482#M20284</link>
      <description>The group by clause is used when summary statistics are requested, such as the min, max, or average.  Since you are not requesting any summary statistics, the group by clause has no impact.  You could use an order by clause instead and subsequently print the results by hhid.</description>
      <pubDate>Tue, 07 Sep 2010 16:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70482#M20284</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2010-09-07T16:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql : error in table creation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70483#M20285</link>
      <description>I think that I might have misunderstood your post the first time I read it.  You should consider using a subquery to find all the IDs which have values of both 6 and 3.  For example:&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as&lt;BR /&gt;
select *&lt;BR /&gt;
from test&lt;BR /&gt;
where product in (6 3) and hhid in &lt;BR /&gt;
	(select hhid &lt;BR /&gt;
	from test&lt;BR /&gt;
	where product = 6&lt;BR /&gt;
	intersect&lt;BR /&gt;
	select hhid&lt;BR /&gt;
	from test where product=3);&lt;BR /&gt;
quit;</description>
      <pubDate>Tue, 07 Sep 2010 17:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70483#M20285</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2010-09-07T17:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql : error in table creation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70484#M20286</link>
      <description>thanks much polingjw! the code was very helpful and i could also modify it to include more items of interest.</description>
      <pubDate>Wed, 08 Sep 2010 03:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70484#M20286</guid>
      <dc:creator>spg</dc:creator>
      <dc:date>2010-09-08T03:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql : error in table creation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70485#M20287</link>
      <description>Hi.&lt;BR /&gt;
you need a 'having' statement to fliter the group.&lt;BR /&gt;
try this.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data patrick;&lt;BR /&gt;
 input id $ product;&lt;BR /&gt;
datalines;&lt;BR /&gt;
101 6&lt;BR /&gt;
101 3&lt;BR /&gt;
101 5&lt;BR /&gt;
101 3&lt;BR /&gt;
102 2&lt;BR /&gt;
102 3&lt;BR /&gt;
102 6&lt;BR /&gt;
102 6&lt;BR /&gt;
103 6&lt;BR /&gt;
103 6&lt;BR /&gt;
103 6&lt;BR /&gt;
103 6&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table test1 as&lt;BR /&gt;
  select *&lt;BR /&gt;
    from patrick&lt;BR /&gt;
      where product in (6 3)&lt;BR /&gt;
        group by id&lt;BR /&gt;
          having count( distinct product) ge 2;&lt;BR /&gt;
run;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Wed, 08 Sep 2010 05:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70485#M20287</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-09-08T05:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql : error in table creation</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70486#M20288</link>
      <description>Thanks Ksharp for the useful tip!</description>
      <pubDate>Thu, 09 Sep 2010 21:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-error-in-table-creation/m-p/70486#M20288</guid>
      <dc:creator>spg</dc:creator>
      <dc:date>2010-09-09T21:52:13Z</dc:date>
    </item>
  </channel>
</rss>

