BookmarkSubscribeRSS Feed
Ashwini_uci
Obsidian | Level 7

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

12 REPLIES 12
Patrick
Opal | Level 21

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.

Ashwini_uci
Obsidian | Level 7

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?

Astounding
PROC Star

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.

Ashwini_uci
Obsidian | Level 7

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;

 

Astounding
PROC Star

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.

Ashwini_uci
Obsidian | Level 7

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

Astounding
PROC Star

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

Ashwini_uci
Obsidian | Level 7

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

ballardw
Super User

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.

Ashwini_uci
Obsidian | Level 7

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?

ballardw
Super User

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?

Ashwini_uci
Obsidian | Level 7

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1944 views
  • 0 likes
  • 4 in conversation