Help using Base SAS procedures

Compute Mean for Cross-tab Columns

Accepted Solution Solved
Reply
Contributor
Posts: 26
Accepted Solution

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: 8,742

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;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,204

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: 8,742

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: 8,742

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:

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 370 views
  • 3 likes
  • 3 in conversation