Search code examples
sasproc

SAS Making Proc FREQ conditional on multiple variables


the structure of my data set is roughly as follows:

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;

Now I would like to make PROC FREQ conditional on two variables (at least). I tried

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

as well as

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

But they don't work and I couldn't find a solution on the web.

Any ideas are greatly welcomed!

Gerit


Solution

  • You were very close:

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

    You can read more about where here: http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000202951.htm