creating a comprehensive crosstabluation table with multiple variables

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

creating a comprehensive crosstabluation table with multiple variables

Hello everyone and thanks in advance for your help,

 

I have a question which I can't seem to wrap my head around for figuring out how to write the code. It's probably not that complicated but I'm having a mental block.

 

I am trying to create a crosstabulation table including data from multiple variables.

I can create tables for each variable but I am not sure how to make one big table with data from all the variables.

 

 

For example,

I have the following tables created via

 

 

data work.temp2;
    set perm.test2;
run;

proc freq data=work.temp2;
    table Facility_Type*(_1 _2)/norow nocol nocum;
run;

 

 

sas tables.jpg


What I would like to do is to essentially combine the tables. So getting one table comprising the total frequency and percent of "IN" and "OUT" for each Facility_Type for the two variables (_1 and _2), instead of one table per variable.

 

Any help you can provide to send me in the right direction would be great.

Thanks


Theresa


Accepted Solutions
Solution
‎09-25-2015 12:54 PM
Super User
Posts: 10,487

Re: creating a comprehensive crosstabluation table with multiple variables

This may be a job for Proc tabulate, especially if you more nesting.

You tell the procedure whether a variable is Class, to provide categories, or Var that would be used for caclulating means, max, min and other statistics.

 

proc tabulate data=work.temp2;
   class facility_type _1 _2;
   table facility ,
             (_1 _2) *(n Pctn); /* has summary in columns*/
   table facility *(n Pctn) ,
             _1 _2 ; /* has summary in rows*/
run;


Note that default behavior for tabulate is that if any CLASS variable has missing values then the entire record is excluded from the summary. To include those records add "/ missing" to the class statement.

 

Also you may have many different table statements in one procedure call.

View solution in original post


All Replies
Solution
‎09-25-2015 12:54 PM
Super User
Posts: 10,487

Re: creating a comprehensive crosstabluation table with multiple variables

This may be a job for Proc tabulate, especially if you more nesting.

You tell the procedure whether a variable is Class, to provide categories, or Var that would be used for caclulating means, max, min and other statistics.

 

proc tabulate data=work.temp2;
   class facility_type _1 _2;
   table facility ,
             (_1 _2) *(n Pctn); /* has summary in columns*/
   table facility *(n Pctn) ,
             _1 _2 ; /* has summary in rows*/
run;


Note that default behavior for tabulate is that if any CLASS variable has missing values then the entire record is excluded from the summary. To include those records add "/ missing" to the class statement.

 

Also you may have many different table statements in one procedure call.

New Contributor
Posts: 2

Re: creating a comprehensive crosstabluation table with multiple variables

Thanks a lot! This is exactly what I was trying to do!


Theresa

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 250 views
  • 1 like
  • 2 in conversation