Programming the statistical procedures from SAS

How to use proc tabulate in making 3*3 tables

Reply
Regular Contributor
Posts: 173

How to use proc tabulate in making 3*3 tables

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

Respected Advisor
Posts: 4,021

How to use proc tabulate in making 3*3 tables

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.

Regular Contributor
Posts: 173

How to use proc tabulate in making 3*3 tables

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?

Super User
Posts: 5,259

How to use proc tabulate in making 3*3 tables

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.

Regular Contributor
Posts: 173

How to use proc tabulate in making 3*3 tables

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;

 

Super User
Posts: 5,259

How to use proc tabulate in making 3*3 tables

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.

Regular Contributor
Posts: 173

How to use proc tabulate in making 3*3 tables

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

Super User
Posts: 5,259

How to use proc tabulate in making 3*3 tables

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).

Regular Contributor
Posts: 173

How to use proc tabulate in making 3*3 tables

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!!

Super User
Posts: 10,880

How to use proc tabulate in making 3*3 tables

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.

Regular Contributor
Posts: 173

How to use proc tabulate in making 3*3 tables

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?

Super User
Posts: 10,880

How to use proc tabulate in making 3*3 tables

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?

Regular Contributor
Posts: 173

How to use proc tabulate in making 3*3 tables

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!!

Ask a Question
Discussion stats
  • 12 replies
  • 261 views
  • 0 likes
  • 4 in conversation