Formatting Variable Values |
Associating User-Defined Formats with
Variables![]() ![]() |
Referencing Your Formats
Remember that permanent, user-defined formats are stored in a format catalog.
For example, the program below stores the format JobFmt in a catalog named
Library.Formats, which is located in the directory
|
|
To use the JobFmt format in a later DATA or PROC step, you must reference
the library with the libref Library.
libname library ' At this point, the Library libref is required. SAS software searches for JobFmt in either of two libraries; the temporary library referenced by the libref Work or a permanent library referenced by the libref Library.
Just as with SAS formats, you associate a user-defined format with a variable in a FORMAT statement. data perm.empinfo; infile empdata; input @9 FirstName $5. @1 LastName $7. +7 JobTitle 3. @19 Salary comma9.; format salary comma9.2 jobtitle jobfmt.; run; Remember, you can place the FORMAT statement in either a DATA or a PROC step. By placing the FORMAT statement in a DATA step, you can permanently associate a format with a variable. Note that you do not have to specify a width value when using a user-defined format.
When you submit the PRINT procedure, output for Perm.Empinfo
now displays the values for proc print data=perm.empinfo; run; |
Obs | FirstName | LastName | JobTitle | Salary |
1 | Donny | Evans | technical writer | 29,996.63 |
2 | Lisa | Helms | text processor | 18,567.23 |
3 | John | Higgins | 25,309.00 | |
4 | Amy | Larson | senior technical writer | 32,696.78 |
5 | Mary | Moore | technical writer | 28,945.89 |
6 | Jason | Powell | manager | 35,099.50 |
7 | Judy | Riley | assoc. technical writer | 25,309.00 |
8 | Neal | Ryan | technical writer | 28,180.00 |
9 | Henry | Wilson | senior technical writer | 31,875.46 |
10 | Chip | Woods | text processor | 17,098.71 |
![]() ![]() ![]() ![]() ![]() ![]() |
|
![]() |
![]() |
Copyright © 2002 SAS Institute Inc.,
Cary, NC, USA. All rights reserved.