我试图找到所有拥有两种产品的公司。我的问题是当我制作一个过滤器时,它当时只在一行上看,所以Product = car AND Product = dog永远不会是真的,因为每行只有一个产品。
我无法通过AND运算符查看'name'列。
+------+-----------------+
| name | productniveau_2 |
+------+-----------------+
| IKEA | car |
| IKEA | dog |
| SAS | house |
+------+-----------------+
答案 0 :(得分:1)
拉斯穆斯, 要获得具有2个产品的公司,您可以执行Proc SQL分组以获得具有该标准的所有产品。
data have;
input Company $4. Product $10.;
cards;
IKEA A24
IKEA A53
IKEA A67
Sear A35
Sear A86
Sear A24
DDDD A35
DDDD A56
AAAA A21
;
run;
proc Sql;
create table wante as
select Company, count(Company) as Count
from have
group by Company
having count(Product) = 2;
quit;
/*having count(Product) > 1 will get you all companies that have more than one product */
如果您需要列出公司和产品,可以使用如下的子查询...
data have;
input Company $4. Product $10.;
cards;
IKEA A24
IKEA A53
IKEA A67
Sear A35
Sear A86
DDDD A35
DDDD A56
AAAA A21
;
run;
proc Sql;
create table want as
select Company, Product
from have
where company in ( select Company
from have
group by Company
having count(Company) = 2);
quit;
答案 1 :(得分:1)