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?
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;
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;
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.
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;
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.
Ready to level-up your skills? Choose your own adventure.