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 ?

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2676 views
  • 0 likes
  • 3 in conversation