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;
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.
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.
Why not use proc tabulate ?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.