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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 782 views
  • 1 like
  • 4 in conversation