SAS VA(SAASNOW) - 过滤和条件交叉行

时间:2016-02-17 15:59:11

标签: filter sas

我试图找到所有拥有两种产品的公司。我的问题是当我制作一个过滤器时,它当时只在一行上看,所以Product = car AND Product = dog永远不会是真的,因为每行只有一个产品。

SASVA

我无法通过AND运算符查看'name'列。

+------+-----------------+
| name | productniveau_2 |
+------+-----------------+
| IKEA | car             |
| IKEA | dog             |
| SAS  | house           |
+------+-----------------+

2 个答案:

答案 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 */

enter image description here

如果您需要列出公司和产品,可以使用如下的子查询...

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;

enter image description here

答案 1 :(得分:1)

首先,您可以根据产品类别构建2个度量:hasCar和hasDog whith定义如下:

enter image description here

接下来创建聚合度量'想要':

enter image description here

在最后一步中,将过滤器放在想要= 1的对象上:

enter image description here