BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GregBond
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

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

4 REPLIES 4
stat_sas
Ammonite | Level 13

Hi,

Which method/procedure are you using for this?

Cynthia_sas
SAS Super FREQ

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;

GregBond
Obsidian | Level 7

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!

Cynthia_sas
SAS Super FREQ

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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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