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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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