Help using Base SAS procedures

proc freq with multiple variables

Reply
Frequent Contributor
Posts: 104

proc freq with multiple variables

Hi SAS community,

I would like to create a crosstab matrix of 10 variables by ID.  Can I do this with proc freq?  (I.e. using a modified code of A*B*C*D*E*F*G*H*I*J?)

Thanks!

data have;

input ID A B C D E F G H I J;

datalines;

21 0 1 0 0 0 0 1 0 0 0

22 0 0 0 1 0 0 0 0 0 0

23 0 0 0 0 0 0 0 0 0 0

24 0 0 0 0 1 1 0 0 0 1

25 0 0 1 0 0 0 0 0 0 0

26 0 0 1 1 1 0 0 0 0 0

27 0 1 0 0 0 0 0 0 0 0

28 0 0 0 0 1 0 1 1 0 0

29 1 0 0 0 0 0 0 0 0 0

30 0 0 0 0 0 0 0 0 0 0

;;

run;

Super User
Posts: 5,099

Re: proc freq with multiple variables

If you want an output data set, it's easy.  Just use the modified code you listed in the TABLES statement, along with these options:

TABLES A*B*C*D*E*F*G*H*I*J / noprint out=my_output_dataset;

If you want a report with a structure that a human might be able to grasp, try the LIST option:

TABLES A*B*C*D*E*F*G*H*I*J / LIST MISSING;

The report can be quite lengthy, as it requires a row for each unique combination of 10 variables.  If this report doesn't have the right appearance that you need, you'll have to switch to another tool such as PROC TABULATE.  The harder part will be deciding on what the report should look like.

Good luck.

Super User
Posts: 5,099

Re: proc freq with multiple variables

It occurred to me that you might be looking for something different, the equivalent of ID*A, then ID*B, then ID*C, etc.  If so, try this variation:

TABLES ID * (A B C D E F G H I J);

Good luck.


Super User
Posts: 9,691

Re: proc freq with multiple variables

Why not use proc tabulate ?

Ask a Question
Discussion stats
  • 3 replies
  • 235 views
  • 0 likes
  • 3 in conversation