FORMAT Procedure
Example 9: Writing Ranges for Character Strings
This example creates
a format and shows how to use ranges with character strings.
Program
libname proclib'SAS-library';
data train;
set proclib.staff(keep=name idnumber);
run;
proc print data=train noobs;
title 'The TRAIN Data Set without a Format';
run;
Program Description
libname proclib'SAS-library';
data train;
set proclib.staff(keep=name idnumber);
run;
Print the data set TRAIN without a format. The NOOBS option suppresses the printing of observation
numbers.
proc print data=train noobs;
title 'The TRAIN Data Set without a Format';
run;
Output
The TRAIN Data Set without a Format
Store the format in WORK.FORMATS. Because the LIBRARY= option does not appear, the
format is stored in WORK.FORMATS and is available only for the current
SAS session.
Create the $SkillTest. format. The
$SKILL. format prints each employee's identification number and the
skills test that they have been assigned. Employees must take either
TEST A, TEST B, or TEST C, depending on their last name. The exclusion
operator (<) excludes the last value in the range. Thus, the first
range includes employees whose last name begins with any letter from
A through D, and the second range includes employees whose last name
begins with any letter from E through M. The tilde (~) in the last
range is necessary to include an entire string that begins with the
letter Z.
value $skilltest 'a'-<'e','A'-<'E'='Test A'
'e'-<'m','E'-<'M'='Test B'
'm'-'z~','M'-'Z~'='Test C';
run;
Generate a report of the TRAIN data set. The
FORMAT= option in the DEFINE statement associates $SkillTest. with
the NAME variable. The column that contains the formatted values of
NAME is using the alias Test. Using an alias enables you to print
a variable twice, once with a format and once with the default format.
See for more information about PROC REPORT.
proc report data=train nowd headskip;
column name name=test idnumber;
define test / display format=$skilltest. 'Test';
define idnumber / center;
title 'Test Assignment for Each Employee';
run;
Output
Test Assignment for Each Employee
Copyright © SAS Institute Inc. All rights reserved.