SAS Formats
SAS Formats
April 9, 2008
CM Solutions Inc.
SAS Formats
A format is an instruction that SAS uses to write data values. Use formats to control the written appearance of data values, or, in some cases, to group data values together for analysis. For example, the WORDS22. format, which converts numeric values to their equivalent in words, writes the numeric value 692 as six hundred ninety-two
April 9, 2008
CM Solutions Inc.
Example
The number 17631 can be written in several ways
data testfmts; retain var1 - var4 17631; run;
Proc print data=testfmts width=min noobs; format var1 comma9. var2 dollar9.2 var3 mmddyy10. var4 mmddyyd10.; run;
April 9, 2008
CM Solutions Inc.
Results
April 9, 2008
CM Solutions Inc.
remains unchanged
April 9, 2008
CM Solutions Inc.
Another example
data testfmts; retain var1 - var4 17631; format var1 comma9. var2 dollar9.2 var3 mmddyy10. var4 mmddyyd10.; run;
April 9, 2008
CM Solutions Inc.
Results
April 9, 2008
CM Solutions Inc.
10
has
April 9, 2008
CM Solutions Inc.
11
April 9, 2008
CM Solutions Inc.
12
April 9, 2008
CM Solutions Inc.
13
April 9, 2008
CM Solutions Inc.
14
April 9, 2008
CM Solutions Inc.
15
April 9, 2008
CM Solutions Inc.
Examples 16
16
value $prov CALGARY, EDMONTON = AB VANCOUVER , FIELD = BC ; value sexfmt 1 = FEMALE 2 = MALE other = ? ;
example 17 17
April 9, 2008
CM Solutions Inc.
April 9, 2008
CM Solutions Inc.
18
April 9, 2008
CM Solutions Inc.
19
April 9, 2008
CM Solutions Inc.
20
April 9, 2008
CM Solutions Inc.
21
April 9, 2008
CM Solutions Inc.
22
April 9, 2008
CM Solutions Inc.
23
April 9, 2008
CM Solutions Inc.
24
April 9, 2008
CM Solutions Inc.
25
26
Other uses
Formats can also be used to emulate table lookups Use the CNTLIN option to specify an input control data set
Must have 3 variables FMTNAME, START and LABEL
April 9, 2008
CM Solutions Inc.
27
April 9, 2008
CM Solutions Inc.
28
29
30
Formats can really make your SAS data management activities more effective and efficient
April 9, 2008
CM Solutions Inc.
31