BookmarkSubscribeRSS Feed
sophia_SAS
Obsidian | Level 7

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;

3 REPLIES 3
Astounding
PROC Star

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.

Astounding
PROC Star

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.


Ksharp
Super User

Why not use proc tabulate ?

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2791 views
  • 0 likes
  • 3 in conversation