Solved
Contributor
Posts: 26

# Compute Mean for Cross-tab Columns

Hi All,

I am trying to compute the mean  for each column when cross-tabbing the variables q46 (categorical) and q118 (nominal; 1,2,3,4,5,6,7......).

Any suggestions? Thanks!

Accepted Solutions
Solution
‎08-26-2014 10:56 AM
SAS Super FREQ
Posts: 9,365

## Re: Compute Mean for Cross-tab Columns

Hi: What code have you tried? Are you using PROC FREQ? PROC TABULATE? PROC REPORT? PROC MEANS? Generally, it would be easier to get the mean using PROC TABULATE than PROC FREQ. And PROC TABULATE will give you percents and statistics like PROC MEANS. Since you did not post data, I made you a test program using SASHELP.SHOES so you can get the idea of how it might work.

Cynthia

ods html file='c:\temp\getmean.html' style=htmlblue;

proc tabulate data=sashelp.shoes f=comma14.2;

class product region;

var sales inventory;

table region all,

sales*(product all)*(n pctsum mean);

table region all,

inventory*product*(min max);

run;

ods html close;

All Replies
Posts: 1,270

## Re: Compute Mean for Cross-tab Columns

Hi,

Which method/procedure are you using for this?

Solution
‎08-26-2014 10:56 AM
SAS Super FREQ
Posts: 9,365

## Re: Compute Mean for Cross-tab Columns

Hi: What code have you tried? Are you using PROC FREQ? PROC TABULATE? PROC REPORT? PROC MEANS? Generally, it would be easier to get the mean using PROC TABULATE than PROC FREQ. And PROC TABULATE will give you percents and statistics like PROC MEANS. Since you did not post data, I made you a test program using SASHELP.SHOES so you can get the idea of how it might work.

Cynthia

ods html file='c:\temp\getmean.html' style=htmlblue;

proc tabulate data=sashelp.shoes f=comma14.2;

class product region;

var sales inventory;

table region all,

sales*(product all)*(n pctsum mean);

table region all,

inventory*product*(min max);

run;

ods html close;

Contributor
Posts: 26

## Re: Compute Mean for Cross-tab Columns

I had been using Proc Freq, however that has given me only the %'s and n's. The code i have been using to get the %'s and n's is a simple one, just:

proc freq data=work.pwl_spss;

table q46*q118;

run;

Cynthia, will the code you posted above work given that I am only using two variables?

Thanks again!

SAS Super FREQ
Posts: 9,365

## Re: Compute Mean for Cross-tab Columns

Hi:

Yes, but you will have to CHANGE the code. And, because TABULATE doesn't make any assumptions, you will have to explicitly ask for the statistics you want. For example, PROC FREQ will automatically give you the N (count), Row Percent, Col Percent and overall percent, but TABULATE will only give you the count or the sum by default. So you have a bit of a TABULATE learning curve. In addition, the TABULATE table is structured differently than the FREQ table. Here are some papers on the subject to get you started:

and, just for fun, here's an example using PROC REPORT http://www.wuss.org/proceedings11/Papers_Miller_E_76116.pdf

cynthia

🔒 This topic is solved and locked.