SAS 使 Proc FREQ 以多个变量为条件

SAS Making Proc FREQ conditional on multiple variables

我的数据集结构大致如下:

data have;
input Name $ year cat var1 var2 var3;
datalines;
adam 2011 1 7 8 7 
bob 2011 2 0 1 0 
clint 2011 1 0 0 0 
adam 2011 9 15 8 9
bob 2011 9 4 56 3 
clint 2011 9 8 4 2
adam 2012 1 4 5 6
bob 2012 2 3 1 1 
clint 2012 1 1 2 3
adam 2012 9 17 8 6
bob 2012 9 17 2 6 
clint 2012 9 13 8 4
;
run;

现在我想让 PROC FREQ 以两个变量为条件(至少)。我试过了

proc freq data=have;
where year = 2012 and where cat=9;
tables var1 * var2;
quit;

以及

proc freq data=have;
where year = 2012;
where cat=9;
tables var1 * var2;
quit;

但它们不起作用,我在网上找不到解决方案。

非常欢迎任何想法!

杰里特

你们非常亲密:

proc freq data=have;
    where year = 2012 and cat=9;
    tables var1 * var2;
quit;

您可以在此处阅读有关 where 的更多信息:http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000202951.htm

当您添加另一个 WHERE 语句时,默认情况下会替换任何已应用的 where 语句。您可以添加关键字 ALSO 以添加到现有位置。

proc freq data=have;
where year = 2012;
where ALSO cat=9;
tables var1 * var2;
quit;