Creating Custom Formats Using the VALUE Statement

Review of Creating Non-Overlapping Formats

You can use the VALUE statement in the FORMAT procedure to create a custom format for displaying data in a particular way. For example, suppose you have airline data and you want to create several custom formats that you can use for your report-writing tasks. You need formats that enable you to do the following:
  • group airline routes into zones
  • label airport codes as International or Domestic
  • group cargo revenue figures into ranges.
The following PROC FORMAT step creates these three formats:
proc format;
   value $routes
         'Route1' = 'Zone 1'
         'Route2' - 'Route4' = 'Zone 2'
         'Route5' - 'Route7' = 'Zone 3'
         ' ' = 'Missing'
         other = 'Unknown';
   value $dest
         'AKL','AMS','ARN','ATH','BKK','BRU',
         'CBR','CCU','CDG','CPH','CPT','DEL',
         'DXB','FBU','FCO','FRA','GLA','GVA',
         'HEL','HKG','HND','JED','JNB','JRS',
         'LHR','LIS','MAD','NBO','PEK','PRG',
         'SIN','SYD','VIE','WLG' = 'International'
         'ANC','BHM','BNA','BOS','DFW','HNL',
         'IAD','IND','JFK','LAX','MCI','MIA',
         'MSY','ORD','PWM','RDU','SEA','SFO' = 'Domestic';
   value revfmt
         . = 'Missing'
         low - 10000 = 'Up to $10,000'
         10000 <- 20000 = '$10,000+ to $20,000'
         20000 <- 30000 = '$20,000+ to $30,000'
         30000 <- 40000 = '$30,000+ to $40,000'
         40000 <- 50000 = '$40,000+ to $50,000'
         50000 <- 60000 = '$50,000+ to $60,000'
         60000 <- HIGH  = 'More than $60,000';
run;
The PROC FORMAT step creates three formats: $ROUTES. and $DEST., which are character formats, and REVFMT., which is numeric.
$ROUTES. groups airline routes into zones. In $ROUTES., the following is true:
  • both single values and ranges are assigned labels
  • missing values are designated by a space in quotation marks and are assigned the label “Missing”
  • the keyword OTHER is used to assign the label “Unknown” to any values that are not addressed in the range
$DEST. labels airport codes as either International or Domestic. In $DEST., the following is true:
  • unique character values are enclosed in quotation marks and separated by commas
  • both missing values and values that are not included in the range are not handled in this format
REVFMT. groups cargo revenue figures into ranges. In REVFMT., the following is true:
  • the less than operator (<) is used to show a non-inclusive range (10000<-20000 indicates that the first value is not included in the range)
  • the keyword LOW is used to specify the lower limit of a variable's value range, but it does not include missing values
  • missing values are designated with a period (.) and assigned the label Missing
  • the keyword HIGH is used to specify the upper limit of a variable's value range

Creating a Format with Overlapping Ranges

There are times when you need to create a format that groups the same values into different ranges. To create overlapping ranges, use the MULTILABEL option in the VALUE statement in PROC FORMAT.
General form, VALUE statement with the MULTILABEL option:
VALUE format-name (MULTILABEL);
Here is an explanation of the syntax:
format-name
is the name of the character or numeric format that is being created.

Example

Suppose you want to create a format that groups dates into overlapping categories. In the table below, notice that each month appears in two groups.
Value
Label
Jan - Mar
1st Quarter
Apr - Jun
2nd Quarter
Jul - Sep
3rd Quarter
Oct - Dec
4th Quarter
Jan - Jun
First Half of Year
Jul- Dec
Second Half of Year
In the PROC FORMAT step below, the MULTILABEL option has been added to indicate that the DATES. format has values with overlapping ranges:
proc format;
   value dates (multilabel) 
         '01jan2000'd - '31mar2000'd = '1st Quarter'
         '01apr2000'd - '30jun2000'd = '2nd Quarter'
         '01jul2000'd - '30sep2000'd = '3rd Quarter'
         '01oct2000'd - '31dec2000'd = '4th Quarter'
         '01jan2000'd - '30jun2000'd = 'First Half of Year'
         '01jul2000'd - '31dec2000'd = 'Second Half of Year';
run; 
Multilabel formatting allows an observation to be included in multiple rows or categories. To use the multilabel formats, you can specify the MLF option on class variables in procedures that support it:
  • PROC TABULATE
  • PROC MEANS
  • PROC SUMMARY
The MLF option activates multilabel format processing when a multilabel format is assigned to a class variable. For example, these statements are true of the following TABULATE procedure code:
  • The FORMAT= option specifies DOLLAR15.2 as the format for the value in each table cell
  • The CLASS statement identifies Date as the class variable and uses the MLF option to activate multilabel format processing.
  • The row dimension of the TABLE statement creates a row for each formatted value of Date.
  • The FORMAT statement references the new format DATES. for the class variable Date.
proc tabulate data = sasuser.sale2000 format = dollar15.2;
   class Date / mlf;
   var RevCargo;
   table Date, RevCargo*(mean median);
   format Date dates.;
run;
RevCargo
Tip
For more information about using the MULTILABEL option, see the SAS documentation for the FORMAT procedure.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.125.205