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
- /
- SAS Programming
- /
- SAS Procedures
- /
- Compute Mean for Cross-tab Columns

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

08-26-2014 10:33 AM

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

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

Posted in reply to GregBond

08-26-2014 10:56 AM

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

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

Posted in reply to GregBond

08-26-2014 10:48 AM

Hi,

Which method/procedure are you using for this?

Solution

08-26-2014
10:56 AM

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

Posted in reply to GregBond

08-26-2014 10:56 AM

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;**

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

Posted in reply to Cynthia_sas

08-26-2014 11:11 AM

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!

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

Posted in reply to GregBond

08-26-2014 12:32 PM

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:

http://www2.sas.com/proceedings/sugi30/258-30.pdf and http://www.lexjansen.com/phuse/2005/ss/ss02.pdf

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

cynthia