Hello everyone
My worry is about having a deep understanding of FORMAT
So i m trying to calculate the average within each range that is created within the format
Following is the code
proc format;
value SalesRange 0 - <100000 = 'Lower'
100000 - <200000 = 'Middle'
200000 - high = 'Upper';
run;
data shoerange;
set sashelp.shoes;
salesreport = put(sales,SalesRange.);
run;
title" sales report";
proc print data = shoerange;
var sales salesreport;
run;
How do i proceed to calculate the average of first range second range and third range
Thanks for your help
Regards
proc format;
value SalesRange 0 - <100000 = 'Lower'
100000 - <200000 = 'Middle'
200000 - high = 'Upper';
run;
data shoerange;
set sashelp.shoes;
salesreport = put(sales,SalesRange.);
run;
PROC MEANS data=shoerange;
CLASS salesreport;
var sales;
run;
/* end of program */
proc format;
value Salesf 0 - <100000 = 'Lower'
100000 - <200000 = 'Middle'
200000 - high = 'Upper';
run;
proc summary data=sashelp.shoes nway;
class sales;
format sales salesf.;
var sales;
output out=want mean=sales_mean/noinherit;
run;
I changed the format name since it has to be 8 characters or less. No need to create a new variable with a PUT statement.
Normally, you would not want to slice the data by a variable (in this case SALES) and then do an analysis (compute the mean) of the same variable (SALES). What is the point? The mean in the Middle group has to be higher than the mean in the lower group, and has to be lower than the mean of the upper group. Normally, the slicing variable is different than the analysis variable.
@PaigeMiller wrote:I changed the format name since it has to be 8 characters or less.
From the docs of proc format:
The name must be a valid SAS name. A numeric format name can be up to 32 characters in length. A character format name can be up to 31 characters in length. If you are creating a character format, then use a dollar sign ($) as the first character.
I must be living in the past. Thanks @andreas_lds
@PaigeMiller wrote: "I changed the format name since it has to be 8 characters or less. No need to create a new variable with a PUT statement."
However, this works fine on my computer (running SAS 9.4):
proc format;
value thisislongerthaneight 1='Hello'
other='nope';
run;
data test;
do i=1 to 5;
output;
j=44;
format i thisislongerthaneight.;
end;
run;
proc summary data=test;
class i;
var j;
output out=mean mean=;
run;
I think that limitation is a bit outdated.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: