Proc tabulate - Specify different column statistics for different row variables

Reply
Occasional Contributor
Posts: 8

Proc tabulate - Specify different column statistics for different row variables

Hello,

I am trying to create a simple table with variables a b and c as rows and I want the statistics N, SUM and mean to be displayed. However, I only want N displayed for variable A and sum and mean displayed for variable B and C like this:

NSUMMEAN
A200
B1000.5
C400.2

PROC TABULATE DATA=ALL  ;

VAR A B C;

TABLE A="A"  B ="B"  C="C"

, (N= "n"  SUM="sum"*F=4.0  MEAN="mean") ;

RUN;

Is there any way to specify different column statistics for different row variables? I don't seem to be able to find any relevant options or examples in SAS documentation.

Thanks so much!

Sarasvati

SAS Super FREQ
Posts: 8,814

Re: Proc tabulate - Specify different column statistics for different row variables

Hi, it's not clear to me what your data set (WORK.ALL) looks like or why you would want a cross-tabular report without a count for B or C and without a SUM for A. Perhaps TABULATE is not the correct procedure for you to use for your data or for the report you want. Generally, you have your CLASS or category variables going down the rows and your numeric variables and the different statistics in the columns. You should be able to run the program below.
    

Cynthia

ods html file='c:\temp\diff_stats.html';

  

proc tabulate data=sashelp.class;

title '1) Requesting Different Statistics in the Column Dimension';

class sex;

var height weight;

table sex all,

      height*n height*mean weight*mean weight*css;

run;

  

proc tabulate data=sashelp.class;

title '2) Requesting Different Statistics in the Row Dimension';

class sex;

var height weight;

table height*n height*mean weight*mean weight*css,

      sex;

run;

   

proc tabulate data=sashelp.class;

title '3) Requesting Different Statistics Without a Category Variable';

var height weight;

table height*n height*mean weight*mean weight*css,

      all;

run;

ods html close;

title;

Occasional Contributor
Posts: 8

Re: Proc tabulate - Specify different column statistics for different row variables

Hi Cynthia,

Thank you for your response. Apologies for not being clearer but allow me to clarify.

I have a dataset of say 200 observations and a number of dichotomous variables coded as 0/1.

I initially created a simple table which produces a row for each dichotomous variable containing the following statistics:

  • N (Total observations),
  • SUM (number of positive responses)
  • MEAN (formatted as a %) to given me the % of positive responses.

If i use these dichotomous variables as class variables I get the zero category as well which I do not want.

However, I now wish to instead put the total number of observations on a row by itself and then list the N (%) for the responses. I have a specific reason that is unique to my problem for wanting to present it in this way.

Variable     Cohort Total     Number positive responses     % pos responses

                        200

VAR1                                                       50                               25.0%

VAR2                                                       25                              12.5%

VAR3                                                       40                               20.0%

It is pretty easy to create the table and later edit out the unwanted numbers in a word processor but i wanted to automate the process.

Any insight into the code that could accomplish this would be appreciated!

Ask a Question
Discussion stats
  • 2 replies
  • 252 views
  • 0 likes
  • 2 in conversation