Professional Documents
Culture Documents
2
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Objectives
Create formats from SAS data sets.
Create permanent formats.
Access permanent formats.
Maintain formats.
3
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Business Scenario
Management has requested that country names, instead
of country codes, be used in reports.
AU 20,000,000 160
CA . 260
DE 80,000,000 394
IL 5,000,000 475
4
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
proc format;
value $country 'AU' = 'Australia'
'CA' = 'Canada'
'DE' = 'Germany'
'IL' = 'Israel'
'TR' = 'Turkey'
'US' = 'United States'
'ZA' = 'South Africa';
run;
5
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
DE Germany $country
IL Israel $country
TR Turkey $country
6
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
DATA Step
Start
Start Label
Label FmtName
FmtName
data country;
keep Start Label FmtName;
retain FmtName '$country';
set orion.country(rename=(Country=Start
Country_Name=Label));
run;
7
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
8
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
data country;
keep Start Label FmtName; Program 1
retain FmtName '$country';
set orion.country(rename=(Country=Start
Country_Name=Label));
run;
data country;
keep Start Label FmtName; Program 2
FmtName='$country';
set orion.country;
Start=Country;
Label=Country_Name;
run;
9
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
a. Program 1
b. Program 2
c. They should be equally efficient.
10
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
a. Program 1
b. Program 2
c. They should be equally efficient.
11
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
work.formats
PROC
PROCFORMAT;
FORMAT;
12
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
13
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
orion.formats
14
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
orion.MyFmts
15
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Viewing Formats
You can use the SAS Explorer window to view formats
stored in a catalog.
16
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
CATALOG Procedure
The CATALOG procedure manages entries in
SAS catalogs.
p210d01
17
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Documenting Formats
You can use the FMTLIB option in the PROC FORMAT
statement to document the format.
proc format library=orion.MyFmts fmtlib;
select $country;
run;
„ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ †
‚ FORMAT NAME: $COUNTRY LENGTH: 13 NUMBER OF VALUES: 7 ‚
‚ MIN LENGTH: 1 MAX LENGTH: 40 DEFAULT LENGTH 13 FUZZ: 0 ‚
‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ…ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚START ‚END ‚LABEL (VER. V7|V8 05MAY2009:12:34:42)‚
‡ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒˆƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‰
‚AU ‚AU ‚Australia ‚
‚CA ‚CA ‚Canada ‚
‚DE ‚DE ‚Germany ‚
‚IL ‚IL ‚Israel ‚
‚TR ‚TR ‚Turkey ‚
‚US ‚US ‚United States ‚
‚ZA ‚ZA ‚South Africa ‚
Šƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ‹ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŒ
p210d01
18
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Nesting Formats
In the VALUE statement, you can specify that the format
use a second format as the formatted value.
Enclose the format name in square brackets:
p210d01
19
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Business Scenario
Use the permanent format $country to specify country
names instead of country codes in the reports.
Country Population Country_ID
AU 20,000,000 160
CA . 260
DE 80,000,000 394
IL 5,000,000 475 orion.MyFmts
Using Formats
By default, when a format is referenced, SAS does the
following:
searches formats supplied by SAS
searches work.formats
writes an error to the log if the format is not found
2 work.formats
21
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
data customers;
set orion.customer;
Country_Name=put(Country,$country.);
run;
22
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
480 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CUSTOMERS may be incomplete. When this step was stopped there were
0 observations and 13 variables.
WARNING: Data set WORK.CUSTOMERS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
481
482 proc freq data=orion.employee_addresses;
483 tables Country;
484 format Country $extra.;
ERROR: The format $EXTRA was not found or could not be loaded.
485 run;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.10 seconds
cpu time 0.00 seconds
23
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
OPTIONS
OPTIONSFMTERR
FMTERR| |NOFMTERR;
NOFMTERR;
24
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
options nofmterr;
25
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
options nofmterr;
26
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
27
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
2 work.formats
3 library.formats
4 orion.formats
5 orion.MyFmts
28
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
29
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
30
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
Maintaining Formats
To maintain formats, perform one of the following tasks:
Edit the PROC FORMAT code that created the original
format.
Create a SAS data set from the format, edit the data
set, and use the CNTLIN= option to re-create the
format.
31
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
33
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
34
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
35
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
36
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
37
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
38
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
39
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
options fmtsearch=(orion.MyFmts);
a. orion.Myfmts only
b. work.formats orion.MyFmts library.formats
formats supplied by SAS
c. formats supplied by SAS work.formats
library.formats orion.MyFmts
d. orion.MyFmts Work.formats library.formats
formats supplied by SAS
40
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
options fmtsearch=(orion.MyFmts);
a. orion.Myfmts only
b. work.formats orion.MyFmts library.formats
formats supplied by SAS
c. formats supplied by SAS work.formats
library.formats orion.MyFmts
d. orion.MyFmts Work.formats library.formats
formats supplied by SAS
41
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
44
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
45
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
46
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
47
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
48
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
49
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
50
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
51
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
52
C o py r i g h t © 2 0 1 4, S A S In s ti t u te I n c . A l l r i g ht s r e s e r v e d .
53
Business Analytics
ST521 – Base SAS I