turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- How to use proc tabulate in making 3*3 tables

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-02-2012 04:04 PM

Hello,

I am wondering how to use proc tabulate to create 2*3 or 3*3 or 4*3 ables that can give me n and % for each cell.

I tried a lot but no luck yet getting what i want.

Any help would be appreciate?

Thanks,

Ashwini

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-02-2012 09:43 PM

It would help if you could provide some sample data (data step creating this data), and then show us how the output should look like.

If you've got already some Proc Tabulate code (even if not working) then posting this one would also help as it possibly demonstrates where you're getting it wrong.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 11:26 AM

this is what it looks like:

**proc** **tabulate** data =library.nismicathcabg4;

class pci cabg;

var diagcath;

tables pci*cabg diagcath*n;

**run**;

i tried various version of this code,i tried the tables syntax in different ways... but it didnot work..

ALL THESE VARIABLES ARE CATEGORICAL WITH 2 LEVELS OF CODES.. 1 :YES, 2: NO

Any idea about how this would work?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-03-2012 10:53 AM

Just wondering ... why must you use PROC TABULATE to do this, when PROC FREQ already does it?

At a minimum, if you use PROC TABULATE you will have to put each number in a separate cell.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 11:15 AM

I tried with proc freq:** but it did not give me the 3*3 tables, it gave 2 separate tables controlling for each category of one variable:**

**The SAS code is as follows: I just want a single 3*3 cross table.. with n or percentages.**

** **

** **

**proc** **freq** data =library.nismicathcabg4;

tables pci*cabg*diagcath;

**run**;

** **

** **

** **

** **

** **

** **

** **

** **

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 11:23 AM

Try this variation on PROC FREQ first, and see if it does what you need:

tables pci*cabg*diagcath / MISSING LIST;

If this isn't what you need, I would have trouble picturing what your report should look like. You might have to give an example.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 11:38 AM

this is 2*2 table, using proc freq pci*cabg... i want 3*3 table same as this one..for pci*cabg*diagcath; with n, colum and row percentages...is there any way to get this in SAS? In SPSS, you can just select as many variables as you want to crosstabulate.... i am not sure how to get it in SAS.

pci cabg

Frequency‚

Percent ‚

Row Pct ‚

Col Pct ‚ 0‚ 1‚ Total

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

0 ‚ 34216 ‚ 7879 ‚ 42095

‚ 41.64 ‚ 9.59 ‚ 51.23

‚ 81.28 ‚ 18.72 ‚

‚ 46.05 ‚ 100.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

1 ‚ 40078 ‚ 0 ‚ 40078

‚ 48.77 ‚ 0.00 ‚ 48.77

‚ 100.00 ‚ 0.00 ‚

‚ 53.95 ‚ 0.00 ‚

ƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒˆ

Total 74294 7879 82173

90.41 9.59 100.00

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 11:49 AM

My imagination must be on vacation today. I appreciate the work you did to get this far, but I can't picture what the table would look like if you added a third variable. I would need to see an example of the table structure that represents 3 variables.

Did you try the LIST option I suggested? It would give you the counts and the overall percentages (not row or column percentages).

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 12:23 PM

yeah, i tried the missing list option, that looks helpful too. Actually if the variables ahd 3 levels, then 3*3 table was possible.. but all these 3 varibales have 2 levels..Somehow i assumed that there are 3 levels and thus was trying to get a 3*3 tables. I guess iwill use the one i got by using proc freq.. 2 seprate tables controlled for each level of one of the 3 variables..

Thanks much for you help!!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 10:53 AM

Also in Tabulate which percentage do you need? Percent of column, row, page or table?

And the n*m behavior is controlled by the number of non-missing levels of your variables, barring some selection coding.

You would be looking at something like:

Proc tabulate data=<your data set name>;

class RowVar ColumnVar;

table rowvar,

columnvar *(n pctn);

run;

This gives % of all records; colpctn or rowpctn to get other percents. You could put all three in the parentheses to see which you want, which then nearly duplicates the behavior of Proc Freq. One difference in the output is results are not "stacked" within a single table cell and your column and row variable labels appear differently in the headers.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 11:41 AM

your examples has only 2 variables,, i am considering 3 variables in 3*3 table..

this is what i tried:

**proc** **tabulate** data =library.nismicathcabg4;

class pci cabg;

var diagcath;

tables pci*cabg diagcath*n;

**run**;

i tried various version of this code,i tried the tables syntax in different ways... but it didnot work..

ALL THESE 3 VARIABLES ARE CATEGORICAL WITH 2 LEVELS OF CODES.. 1 :YES, 2: NO

Any idea about how this would work?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 03:52 PM

Tabulate separates each part of a table, row, column or page, by commas. If there is one comma, such as in my example afte rowvar then it is building a two-dimensional table with rows and columns. If there is another variable AND COMMA, before the row that is a PAGE level and will create a two-dimensional table for each level of the page variable.

If you cross categorical variables as PCI*CABG in your example you are nesting them. You would get

Pci cabg

1 1

2

2 1

2

if you wanted the count of each level DIAGCATH by the other two, you want it to be a CLASS variable as well

possibly you are looking for

table pci*cabg,

diagcath*n; /* with diagcath as CLASS*/

I don't think you're going to get a 3*3 table out of variables with 2 levels.

Can you post an example of what you want the output to look like?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

03-05-2012 07:03 PM

you are right! Actually only if the variables ahd 3 levels, then 3*3 table was possible.. but all these 3 varibales have 2 levels..Somehow i assumed that there are 3 levels and thus was trying to get a 3*3 tables. I guess iwill use the one i got by using proc freq.. 2 seprate tables controlled for each level of one of the 3 variables..same as what you have shown above.

Thanks much for you help!!