FORMAT Procedure

Example 13: Creating a Format for Trafficlighting

Features:

PROC FORMAT statement:: VALUE

Other features:

PROC PRINT statement:: VAR statement STYLE option

Details

This example expands on Writing a Format for Dates Using a Standard SAS Format to use trafficlighting. If an employee is eligible for the benefit, the table cell background for the hire date is green. If the employee is not eligible for the benefit, the table cell background hire date is red.
To create the trafficlighting, the program is enhanced by adding these statements:
  • In the FORMAT procedure, a VALUE= statement creates a format to specify which values receive the red or green table cell background.
  • In the PRINT procedure, a VAR statement for the hiredate variable specifies the background format.

Program

proc format library=library;
   value color    
      low-'31DEC1999'd='green'
		 '01JAN2000'd-high='red';
run;
proc print data=proclib.staff noobs;
   var name idnumber;
   var hiredate / style={background=color.};
 
   title 'PROCLIB.STAFF Using the COLOR. Format'
run;

Program Description

Create the COLOR. format.Hire dates before January 1, 2000 will display l background color of green. Dates beginning with January 1, 2000 and later will display a background of red.
proc format library=library;
   value color    
      low-'31DEC1999'd='green'
		 '01JAN2000'd-high='red';
run;
Use the COLOR. format for the hiredate variable.Use two VAR statements to specify the variables to print. The first VAR statement identifies the variables that are not formatted with the COLOR. format. In the second VAR statement, you specify the COLOR. format using the STYLE option BACKGROUND attribute.
proc print data=proclib.staff noobs;
   var name idnumber;
   var hiredate / style={background=color.};
 
   title 'PROCLIB.STAFF Using the COLOR. Format'
run;
Trafficlighting Using the COLOR. Format
Trafficlighting Using the COLOR. Format