【问题标题】:SAS Making Proc FREQ conditional on multiple variablesSAS 使 Proc FREQ 以多个变量为条件
【发布时间】:2016-01-29 09:41:58
【问题描述】:

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

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;

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

非常欢迎任何想法!

格瑞特

【问题讨论】:

    标签: sas proc


    【解决方案1】:

    你们很亲密:

    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

    【讨论】:

    • “珍惜生活中简单的东西!”非常感谢您的帮助! (我扯了扯头发……)
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      相关资源
      最近更新 更多