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

data shoerange;
set sashelp.shoes;
run;

proc format;
value salegrp
0 - < 100000 = 'Lower'
100000 - 200000= 'Middle'
other ='Upper'
;
run;

proc freq data=shoerange;
format sales salegrp.;
table sales;

 

Does someone know what I should add to that code to get the mean value of the middle sale group?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Freq doesn’t do means, but means does counts. 
I don’t know if the second set of code works here but I wouldn’t expect it to. You can create a new variable that’s identical and use It instead of sales. 

Proc means data = shoerange ;
Var sales;
Run; 

Proc means data = shoerange;
Class sales;
Format sales salegrp.;
Var sales;
Run;

Data shoerange;
Set sadhelp.shoes;
Sales_grp = sales;
Format sales_grp salesgrp.;
Run;

Proc means data = shoerange;
Class sales_grp;
Var sales;
Run;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @alepage  For mean value, shouldn't you be looking at Proc means/summary rather than proc freq. Or am i missing something?

 




data shoerange;
set sashelp.shoes;
run;

proc format;
value salegrp
0 - < 100000 = 'Lower'
100000 - 200000= 'Middle'
other ='Upper'
;
run;

proc means data=shoerange nway mean;
class sales ;
var sales ;
format sales salegrp.;
run;
mkeintz
PROC Star

PROC FREQ provides frequencies of categorical variables, not the mean (or std, min, max, range, etc.) of interval/cardinal variables.  You should use something like proc means:

 

data shoerange;
  set sashelp.shoes;
  if sales  >=200000 then group='Upper ';  else
  if sales  >=100000 then group='Middle'; else
  if sales  >=0       then group='Lower ';
run;
proc means;
  var sales;
  class group;
run;

Because the same original variable (SALES) is used both for classification and as the analysis variable, the most direct solution is to make a second variable (group) and use it in the CLASS statement.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Reeza
Super User

Freq doesn’t do means, but means does counts. 
I don’t know if the second set of code works here but I wouldn’t expect it to. You can create a new variable that’s identical and use It instead of sales. 

Proc means data = shoerange ;
Var sales;
Run; 

Proc means data = shoerange;
Class sales;
Format sales salegrp.;
Var sales;
Run;

Data shoerange;
Set sadhelp.shoes;
Sales_grp = sales;
Format sales_grp salesgrp.;
Run;

Proc means data = shoerange;
Class sales_grp;
Var sales;
Run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 1101 views
  • 1 like
  • 4 in conversation