BookmarkSubscribeRSS Feed
Armand_B
Calcite | Level 5

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

6 REPLIES 6
sbxkoenk
SAS Super FREQ
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 */
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
andreas_lds
Jade | Level 19

@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.


 

PaigeMiller
Diamond | Level 26

I must be living in the past. Thanks @andreas_lds 

--
Paige Miller
s_lassen
Meteorite | Level 14

@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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 913 views
  • 3 likes
  • 6 in conversation