Professional Documents
Culture Documents
Objectives
Create user-defined formats using the
FORMAT procedure.
Apply user-defined formats to variables
in a list report.
Permanently store the formats you
create.
Associate your formats with variables .
Emp
ID
Last
Name
1
2
3
4
5
6
7
8
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
Job
Code
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
Annual
Salary
$50,221.62
$23,666.12
$21,957.71
$96,387.39
$32,278.40
$24,161.14
$59,803.16
$120,202.38
3
Last
Name
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
JobCode
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
Pilot
Flight
Flight
Pilot
Flight
Flight
Pilot
Pilot
Annual
Salary
Attendant
Attendant
Attendant
Attendant
More than
Less than
Less than
More than
25,000 to
Less than
More than
More than
50,000
25,000
25,000
50,000
50,000
25,000
50,000
50,000
Creating User-defined
General form Formats
of a PROC FORMAT step:
PROC
PROCFORMAT
FORMAT<options>;
<options>;
VALUE
VALUE format-name
format-namerange1='label
range1='label' '
range2='label
range2='label' '
.... ..;;
RUN;
RUN;
Useful
UsefulOptions
Options are
are
LIBRARY
LIBRARY== libref
libref specify
specifythe
thelibref
libreffor
foraaSAS
SASdata
datalibrary
libraryfor
foraa
permanent
permanentcatalog
catalogininwhich
whichuser-defined
user-definedformats
formatsare
arestored.
stored.
FMTLIB
FMTLIB prints
printsthe
thecontents
contentsof
ofaaformat
formatcatalog.
catalog.
Creating User-defined
Formats
Labels
can be up to 32,767 characters in length
are typically enclosed in quotes,
although it is not required.
Range(s)
can be single values
ranges of values.
Creating User-defined
Formats
Formatted
Assign labels to single numbers.
proc format;
value gender 1='Female'
2='Male'
other='Miscoded';
run;
Numeric
format
name
Numeric data
value
value
Keyword
Creating User-defined
Assign labelsFormats
to ranges of numbers.
Keyword
proc format;
value boardfmt low-49='Below'
50-99='Average'
100-high='Above Average';
run;
Numeric data ranges
10
Creating User-defined
Formats
Assign labels to
character values and
ranges of character values.
Character
format name
proc format;
value $gradefm 'A'='Good'
'B'-'D'='Fair'
'F'='Poor'
'I','U'='See Instructor'
other='Miscoded';
run;
Character
value range
Discrete
character
values
Keyword
11
Creating User-defined
Formats
proc format;
value $codefmt 'FLTAT'='Flight Attendant'
'PILOT'='Pilot';
run;
$codefmt
Step 2: Apply the format.
proc print
data=mylib.empdata;
format JobCode $codefmt.;
run;
12
Creating User-defined
Formats
Step 1: Create the format.
proc format;
value money low-<25000 ='Less than 25,000'
25000-50000='25,000 to 50,000'
50000<-high='More than 50,000';
run;
money
proc print
data=mylib.empdata;
format Salary money.;
run;
13
Creating User-defined
Formats
14
Applying User-defined
Formatssplit=' ' noobs;
print data=mylib.empdata
proc
label LastName='Last Name'
FirstName='First Name'
Salary='Annual Salary';
format Jobcode $codefmt. Salary money.;
title1 'Salary Report in Categories';
run;
Salary Report in Categories
Emp
ID
Last
Name
0031
0040
0071
0082
0091
0106
0355
0366
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
First
Name
JobCode
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
Pilot
Flight
Flight
Pilot
Flight
Flight
Pilot
Pilot
Annual
Salary
Attendant
Attendant
Attendant
Attendant
More than
Less than
Less than
More than
25,000 to
Less than
More than
More than
50,000
25,000
25,000
50,000
50,000
25,000
50,000
50,000
15
17
NUMBER OF
VALUES:
3
MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH
FUZZ: STD
-------------------------------------------------------------------------------------------------------START
END
LABEL (VER. V7|V8
26SEP2010:21:06:03)
--------------------------------------------------------------------------------------------------------LOW
30000
Low
30001
60000
Moderate
60000
HIGH
High
16 NUMBER OF VALUES: 2
MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH 16 FUZZ:
-----------------------------------------------------------------------------------------------------START
END
LABEL (VER. V7|V8 26SEP2010:21:06:03)
-----------------------------------------------------------------------------------------------------FLTAT
FLTAT
Flight Attendant
PILOT
PILOT
Pilot
-------------------------------------------------------------------------------------------------------
NOTE: The default Length is the length of the largest format value.
For this example, there are 16 characters for value: Flight Attendant
19
21
In this example,
A permanent format
catalog:
fmtemp2.formats
is created.
The OPTIONS
statement directs SAS to
look for
The format catalog :
fmtemp2.formats
25
Exercise 1
Open the program c71.sas. The data set
reported in this program is the Empdata data:
Obs
1
2
3
4
5
6
7
8
Emp
ID
0031
0040
0071
0082
0091
0106
0355
0366
LastName
GOLDENBERG
WILLIAMS
PERRY
MCGWIER-WATTS
SCOTT
THACKER
BELL
GLENN
FirstName
DESIREE
ARLENE M.
ROBERT A.
CHRISTINA
HARVEY F.
DAVID S.
THOMAS B.
MARTHA S.
Job
Code
Salary
PILOT
FLTAT
FLTAT
PILOT
FLTAT
FLTAT
PILOT
PILOT
50221.62
23666.12
21957.71
96387.39
32278.40
24161.14
59803.16
120202.38
26
Program 1: Write a SAS program to read this data from your MYLIB library
and perform the following tasks:
1.Define the user-defined format as a Temporary format catalog for
variables. And make sure to list the formats you created using FMTLIB
option in your PROC FORMAT procedure.
Jobcode: PILOT as Pilot , FLTAT as Flight Attendant
Salary: low 30000 as Low, 30001-60000 as Moderate,
60000 High as High
2. Use the format as a local format statement in the PROC Print procedure.
Program 2:
1.Revise the program 1 above to create a Permanent format catalog using
LIBRARY as libref, which is stored in c:\Math660\fmt1 folder.
2.Use the permanent formant statement in your data step, and print the
data
Program 3: Revise your program 2 to do the following tasks for defining
user-define format:
1.Define a LIBREF, permfmt, that connect to the path c:\Math660\fmt2
2.Write the OPTIONS statement to inform SAS the format search sequence
OPTIONS fmtsearch = (permfmt);
27