+ All Categories
Home > Documents > SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent...

SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent...

Date post: 09-May-2020
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
68
SAS ® Formats and the FORMAT Procedure Course Notes
Transcript
Page 1: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

SAS® Formats and the FORMAT Procedure

Course Notes

Page 2: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

SAS® Formats and the FORMAT Procedure Course Notes was developed by Christine Riddiough. Editing and production support was provided by the Curriculum Development and Support Department.

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. Other brand and product names are trademarks of their respective companies.

SAS® Formats and the FORMAT Procedure Course Notes

Copyright © 2011 SAS Institute Inc. Cary, NC, USA. All rights reserved. Printed in the United States of America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher, SAS Institute Inc.

Book code E2096, course code UGFMTS, prepared date 27Sep2011. UGFMTS_001

Page 3: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

For Your Information iii

Table of Contents

Chapter 1 Formatting Basics ................................................................................ 1-1

1.1 Creating and Using Formats ............................................................................................ 1-3

Chapter 2 Format Utilities ..................................................................................... 2-1

2.1 Introduction ...................................................................................................................... 2-3

2.2 Creating Permanent Formats ............................................................................................ 2-4

Demonstration: Creating Permanent Fonts ............................................................... 2-8

2.3 Using SAS Data Sets to Create Formats ........................................................................ 2-10

Demonstration: Creating Formats from Data Sets .................................................. 2-13

2.4 The PICTURE and INVALUE Statements .................................................................... 2-15

Demonstration: Using the PICTURE Statement ..................................................... 2-18

Demonstration: Using the INVALUE Statement .................................................... 2-23

Chapter 3 Format Uses .......................................................................................... 3-1

3.1 Introduction ...................................................................................................................... 3-3

3.2 Grouping Data .................................................................................................................. 3-4

Demonstration: Grouping Data ................................................................................. 3-6

3.3 Table Lookups ................................................................................................................ 3-10

Demonstration: Table Lookups ............................................................................... 3-13

3.4 Formats for Display ....................................................................................................... 3-15

Demonstration: Using Formats for Display ............................................................ 3-20

Chapter 4 New in SAS® 9.3 .................................................................................... 4-1

4.1 Introduction ...................................................................................................................... 4-3

4.2 Viewing Formats and Using Functions ............................................................................ 4-4

Page 4: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

iv For Your Information

Demonstration: New Features in SAS 9.3 ................................................................ 4-6

Page 5: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

For Your Information v

To learn more…

For information about other courses in the curriculum, contact the SAS Education Division at 1-800-333-7660, or send e-mail to [email protected]. You can also find this information on the Web at support.sas.com/training/ as well as in the Training Course Catalog.

For a list of other SAS books that relate to the topics covered in this Course Notes, USA customers can contact our SAS Publishing Department at 1-800-727-3228 or send e-mail to [email protected]. Customers outside the USA, please contact your local SAS office.

Also, see the Publications Catalog on the Web at support.sas.com/pubs for a complete list of books and a convenient order form.

Page 6: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

vi For Your Information

Page 7: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

Chapter 1 Formatting Basics

1.1 Creating and Using Formats .......................................................................................... 1-3

Page 8: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

1-2 Chapter 1 Formatting Basics

Page 9: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

1.1 Creating and Using Formats 1-3

1.1 Creating and Using Formats

4

Objectives Use the FORMAT statement.

Define the FORMAT procedure syntax.

4

5

Displaying Data ValuesYou can enhance reports by using SAS formats to format data values.

5

SASDataSet

Format Report

Values in the SAS data set are not changed.

Page 10: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

1-4 Chapter 1 Formatting Basics

6

Formatting Data ValuesTo apply a format to a specific SAS variable, use the FORMAT statement. General form of the FORMAT statement:

Example:

6

FORMAT variable(s) format;

proc print data=ia.empdata;format Salary dollar11.2;

run;

7

Creating User-Defined FormatsGeneral form of a PROC FORMAT step:

7

PROC FORMAT;VALUE format-name range1='label'

range2='label'…;

RUN;

To create your own formats, use the FORMAT procedure.

In addition to the VALUE statement, you can define formats for numbers using the PICTURE statement and informats using the INVALUE statement.

Page 11: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

Chapter 2 Format Utilities

2.1 Introduction ..................................................................................................................... 2-3

2.2 Creating Permanent Formats ........................................................................................ 2-4

Demonstration: Creating Permanent Fonts ........................................................................... 2-8

2.3 Using SAS Data Sets to Create Formats .................................................................... 2-10

Demonstration: Creating Formats from Data Sets ............................................................... 2-13

2.4 The PICTURE and INVALUE Statements .................................................................... 2-15

Demonstration: Using the PICTURE Statement .................................................................. 2-18

Demonstration: Using the INVALUE Statement ................................................................... 2-23

Page 12: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-2 Chapter 2 Format Utilities

Page 13: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.1 Introduction 2-3

2.1 Introduction

3

Objectives Create permanent formats.

Use data sets to create formats.

Define the PICTURE and INVALUE statements.

3

Page 14: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-4 Chapter 2 Format Utilities

2.2 Creating Permanent Formats

5

General Form of a PROC FORMAT StepTo create a permanent format, add the LIBRARY= option to the PROC FORMAT statement:

5

PROC FORMAT LIBRARY=libref.catalog;…

Without the LIBRARY= option, formats are stored in the work.formats catalog and exist for the duration of the SAS session.

If the LIBRARY= option specifies only libref, formats are stored permanently in libref.formats.

If the LIBRARY= option specifies libref.catalog, formats are stored permanently in that catalog.

Page 15: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.2 Creating Permanent Formats 2-5

6

How Are Formats Stored? Formats are stored as SAS catalogs entries.

A single SAS catalog can contain several catalog entries.

6

revfmt.format dest.formatc routes.format

SAS Catalog ia.formats

SAS catalogs are special SAS files that store many different types of information in smaller units named entries.

7

Using the FMTSEARCH System OptionTo use permanent formats or to search multiple catalogs, use the FMTSEARCH= system option to identify the catalog(s) to be searched for the format(s).

General form of the FMTSEARCH= system option:

7

OPTIONS FMTSEARCH=(item-1 item-2…item-n);

Page 16: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-6 Chapter 2 Format Utilities

8

Using the FMTSEARCH System Option

8

SAS Supplied Formats

work.formats

ia.formats

ia. formats2

options fmtsearch=(ia ia.formats2);

...

9

Using the NOFMTERR OptionBy default, the FMTERR system option is in effect. If you use a format that SAS cannot load, SAS issues an error message and stops processing the step.

To prevent the default action, change the system option FMTERR to NOFMTERR.

9

OPTIONS FMTERR | NOFMTERR;

Page 17: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.2 Creating Permanent Formats 2-7

10

The CATALOG ProcedureThe CATALOG procedure manages entries in SAS catalogs.

Some functions of PROC CATALOG

create a listing of the contents of a catalog

copy a catalog or selected entries within a catalog

rename or delete entries within a catalog

modify the description of a catalog entry.

10

11

Documenting FormatsYou can use the FMTLIB option in the PROC FORMAT statement to document the format.

General form of the FMTLIB option:

11

PROC FORMAT LIBRARY=libref.catalogFMTLIB;<other statements>;

RUN;

Page 18: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-8 Chapter 2 Format Utilities

Creating Permanent Fonts

/* *************************************************** */ /* Program: f2d1.sas */ /* *************************************************** */ /* This program demonstrates how to create permanent */ /* formats and how to manage them. */ /* *************************************************** */ libname ia '.'; ** Create formats in the ia.formats catalog.; proc format library=ia; value $emplev 'PRES' = 'Level A' 'VICEPR' = 'Level B' 'BAGCLK', 'CHKCLK', 'FACCLK', 'SALCLK', 'FACMNT', 'FINACT', 'FLSCHD', 'RECEPT', 'TELOP' = 'Level 1' 'FINCLK', 'FSVCLK', 'HRCLK', 'ITCLK', 'MKTCLK', 'RESCLK' = 'Level 2' 'BAGSUP', 'CHKSUP', 'ITPROG' = 'Level 3' 'GRCSUP', 'ITSUPT' = 'Level 4' 'FLTAT1'-'FLTAT3', 'GRCREW', 'MECH01'-'MECH03', 'PILOT1'-'PILOT3' = 'Level 5' 'FACMGR', 'FINMGR', 'FLSMGR', 'FSVMGR', 'HRMGR', 'ITMGR', 'MKTMGR', 'OFFMGR', 'RESMGR', 'SALMGR' = 'Level 6'; value $dest 'AKL','AMS','ARN','ATH','BKK','BRU','CBR','CCU', 'CDG','CPH','CPT','DEL','DXB','FBU','FCO', 'FRA','GLA','GVA','HEL','HKG','HND','JED', 'JNB','JRS','LHR','LIS','MAD','NBO','PEK', 'PRG','SIN','SYD','VIE','WLG' = 'International' 'ANC','BHM','BNA','BOS','DFW','HNL','IAD','IND', 'JFK','LAX','MCI','MIA','MSY','ORD','PWM', 'RDU','SEA','SFO' = 'Domestic' other='*Unknown Airport*'; run; ** Create a format in the ia.fmt catalog.; proc format library=ia.fmt; value money low - 30000 = 'Low' 30000 <- 55000 = 'Average' 55000 <- high = 'High'; run;

(Continued on the next page.)

Page 19: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.2 Creating Permanent Formats 2-9

** Use options to ensure the formats are found.; options fmtsearch=(ia ia.fmt); options nofmterr; ** Use proc catalog to manage format catalogs.; filename fmt 'formats.txt'; proc catalog catalog=ia.fmt et=format; contents file=fmt; run; copy out = ia.formats; select money; run; delete money; run; quit; ** Use the fmtlib option to document formats.; proc format library=ia fmtlib; run;

Partial Output

Page 20: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-10 Chapter 2 Format Utilities

2.3 Using SAS Data Sets to Create Formats

14

Using a Control Data Set to Create a FormatYou can create a format from a SAS data set that contains value information (called a control data set).Use the CNTLIN= option to read the data and create the format.

General form of CNTLIN= option:

14

PROC FORMAT LIBRARY=libref.catalogCNTLIN=SAS-data-set;

RUN;

Page 21: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.3 Using SAS Data Sets to Create Formats 2-11

15

Using a Control Data Set to Create a FormatTo use an input data set to create a format, the data set must contain the variables FMTNAME, START, and LABEL.

15

Example:

data aports; keep Start Label Fmtname; retain fmtname '$airport'; set ia.cities (rename = (Code = Start City = Label)); run;

FMTNAME Character variable whose value is the format or informat name

START Character variable that gives the range's starting value

LABEL Character variable whose value is the informatted or formatted value or the name of a standard SAS informat or format

Other variables are possible.

Page 22: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-12 Chapter 2 Format Utilities

16

Maintaining Permanent FormatsTo maintain formats, you might need to output the formats to a data set.

General form of PROC FORMAT with the CNTLOUT= option:

16

PROC FORMAT LIBRARY=libref.catalogCNTLOUT=SAS-data-set;<other statements>;

RUN;

To maintain a format, you do the following:

• Use CNTLOUT= to create a data set

• Add, update, or delete observations in the data set

• Use CNTLIN= to re-create the format

Page 23: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.3 Using SAS Data Sets to Create Formats 2-13

Creating Formats from Data Sets

/* *************************************************** */ /* Program: f2d2.sas */ /* *************************************************** */ /* Create and maintain a format based on a data set. */ /* *************************************************** */ ** Determine the structure of the original data set.; title 'IA.CITIES'; proc print data=ia.cities; run; proc contents data=ia.cities; run; ** Build the control data set.; data citfmt(keep=start label fmtname); set ia.cities(rename=(code=start city=label)); retain fmtname '$city'; run; ** Use the control data set to create the new format.; proc format cntlin=citfmt; run; ** Use the format as we would any other.; proc print data=ia.delay; where date eq '01mar1995'd; var orig dest delay; format orig dest $city.; title 'Using the new format for ORIG and DEST'; run; ** Convert the format into a control data set.; proc format cntlout=citfmt; select $city; run;

(Continued on the next page.)

Page 24: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-14 Chapter 2 Format Utilities

** Update the control data set with the new cities; proc sql; insert into citfmt set fmtname='$city',start='LGA',end='LGA',label='New York, NY'; insert into citfmt set fmtname='$city',start='YYZ',end='YYZ',label='Toronto'; insert into citfmt set fmtname='$city',start='DCA',end='DCA',label='Washington, DC'; insert into citfmt set fmtname='$city',start='PAR',end='PAR',label='Paris'; insert into citfmt set fmtname='$city',start='LON',end='LON',label='London'; quit; ** Re-create the format with the new values; proc format cntlin=citfmt; run; ** Rerun the report.; proc print data=ia.delay; where date eq '01mar1995'd; var orig dest delay; format orig dest $city.; title 'Using the updated format for ORIG and DEST'; run;

Partial Output

Page 25: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.4 The PICTURE and INVALUE Statements 2-15

2.4 The PICTURE and INVALUE Statements

19

The PICTURE StatementThe PICTURE statement in PROC FORMAT defines a template for data values.

19

PROC FORMAT;PICTURE name

value-range-set-1 <(picture-1-option(s))>;RUN;

20

The PICTURE StatementOptions available with the PICTURE statement include the following:

NOEDIT Specify that numbers are messagecharacters rather than digit selectors.

PREFIX= Specify a character prefix for theformatted value.

FILL= Specify a character that completes the formatted value.

MULT= Specify a number to multiply the variable'svalue by before it is formatted.

20

Page 26: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-16 Chapter 2 Format Utilities

21

The DATATYPE Picture OptionThe DATATYPE picture option specifies that this picture is to apply to a SAS date, SAS time, or SAS datetime value.

21

PROC FORMAT;PICTURE name

value-range-set-1 (DATATYPE=DATE|TIME|DATETIME);

RUN;

Page 27: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.4 The PICTURE and INVALUE Statements 2-17

22

Directives on a PICTURE Statement LOW and HIGH are keywords that signify the lowest

data value and the highest data value.

The % followed by a letter indicates a directive.

22

proc format;picture myfmt

low-high = '%0d-%b-%Y'(datatype = date);

run;

The 0 in the directive indicates whether the day of the month is one digit. Precede that digit with a zero.

Directives include the following:

%a Locale's abbreviated weekday name

%A Locale's full weekday name

%b Locale's abbreviated month name

%B Locale's full month name

%d Day of the month as a decimal number (1-31), with no leading zero

%m Month as a decimal number (1-12), with no leading zero

%Y Year with century as a decimal number

Page 28: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-18 Chapter 2 Format Utilities

Using the PICTURE Statement

/* *************************************************** */ /* Program: f2d3.sas */ /* *************************************************** */ /* This program demonstrates how to use the PICTURE */ /* statement in PROC FORMAT. */ /* *************************************************** */ ** Use mult= option to convert data.; proc format; picture feet other='000000009' (mult=5280); run; data feet; input miles @@; format miles feet.; cards; 1 1.5 2 ; run; proc print data=feet; title 'Converting Miles to Feet'; run; ** Use the mult and prefix options.; proc format; picture curr low-high='000,000' (mult=.001 prefix='$'); run; proc print data=ia.crew(obs=20) label; format salary curr.; label salary='Salary in Thousands'; title 'Picture Format Multiplier'; run; ** Use the fill and prefix options.; proc format; picture salary low-high='00,000,000.00' (fill='*' prefix='$'); run; proc print data=ia.crew(obs=20); format salary salary.; title 'Picture Format Fill Character'; run;

(Continued on the next page.)

Page 29: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.4 The PICTURE and INVALUE Statements 2-19

** Using placeholders and the noedit option.; proc format; picture delGrp low-< 0 = 'Early Arrival' 0 = 'No Delay' 1 = '1 Minute Delay' 1 <- 10 = '09 Minutes Delay' 10<-high= ' Delay Greater than 10 Minutes' (noedit); picture delGx low-< 0 = 'Early Arrival' 0 = 'No Delay' 1 = '1 Minute Delay' 1 <- 10 = '99 Minutes Delay' 10<-high= ' Delay Greater than 10 Minutes' (noedit); picture delGy low-< 0 = 'Early Arrival' 0 = 'No Delay' 1 = '1 Minute Delay' 1 <- 10 = '09 Minutes Delay' 10<-high= ' Delay Greater than 10 Minutes'; run;

proc report data=ia.delay(obs=20) nowd; column delay delay=del delay=dx; define delay / display format=delgrp. 'NOEDIT with 09'; define del / format=delgx. 'NOEDIT with 99'; define dx / format=delgy. '09 without NOEDIT'; title 'Variations of Picture Formats'; run;

** Create a custom date format.; proc format; picture hirefmt low-high = '%0d-%b-%Y ' (datatype=date); run; proc print data=ia.crew(obs=20); var firstname lastname hiredate; format hiredate hirefmt.; title 'Crew Hire Dates with Custom Date Format'; run;

** Use date directives with other text.; proc format; picture mrg low-<'01apr1990'd = 'Pre-Merger' '01apr1990'd-'31mar1993'd = '%B during Merger Process ' (datatype=date) other = 'Post-Merger'; run; proc print data=ia.crew(obs=20); var firstname lastname hiredate; format hiredate mrg.; title 'Crew Hire Dates with Text/Date Format'; run;

Page 30: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-20 Chapter 2 Format Utilities

Partial Output

Page 31: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.4 The PICTURE and INVALUE Statements 2-21

24

PROC FORMAT INVALUE Statement

24

PROC FORMAT LIBRARY=libref.catalog;INVALUE $charinfmt 'value1' = 'informatted-value-1'

'value2' = 'informatted-value-2''valuen' = 'informatted-value-n';

INVALUE numinfmt 'value1' = informatted-value-1'value2' = informatted-value-2'valuen' = informatted-value-n;

RUN;

25

Special Keywords _SAME_ indicates that a value in the domain is to be

mapped into the same value in the range.

_ERROR_ indicates that a value or set of values should be excluded from the domain.

25

Page 32: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-22 Chapter 2 Format Utilities

26

UPCASE Option The UPCASE option automatically uppercases all

input values before they are compared to the informat domain.

This option is used in an INVALUE statement when creating an informat.

26

Page 33: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.4 The PICTURE and INVALUE Statements 2-23

Using the INVALUE Statement

/* *************************************************** */ /* Program: f2d4.sas */ /* *************************************************** */ /* This program demonstrates how to use the INVALUE */ /* statement in PROC FORMAT. */ /* *************************************************** */ proc format; invalue eval 'Excellent'=4 'Good'=3 'Fair'=2 'Poor'=1 ; run; data evals; input EmployeeId $ @6 Evaluation eval. @6 String $9.; datalines; 2355 Good 5889 2 3878 Excellent 4409 Poor 0740 Fair 2398 Excellent 4421 3 7385 Good ; run; title 'Data Read using a Custom Informat'; proc print data=evals; run; proc means data=evals; run; ** Use _same_ and _error_ keywords; proc format; invalue tryit 1-10 = _same_ other = _error_ ; run;

(Continued on the next page.)

Page 34: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-24 Chapter 2 Format Utilities

data same; infile datalines; input @1 Original @1 Stored tryit.; datalines; 5 15 ; run; proc print data=same; title 'Data Read using _SAME_ and _ERROR_'; run; ** Use the upcase option; proc format; invalue $Gender (upcase) 'M' = 'Male' 'F' = 'Female' ; invalue $Genx 'M' = 'Male' 'F' = 'Female' ; run; data gendtest; input @1 Original $ @1 WithUpcase: $gender. @1 NoUpcase : $genx. ; cards; M m f F ; run; proc print data=gendtest; title 'Data Read using UPCASE option'; run;

Page 35: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2.4 The PICTURE and INVALUE Statements 2-25

Partial Output

Page 36: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

2-26 Chapter 2 Format Utilities

Page 37: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

Chapter 3 Format Uses

3.1 Introduction ..................................................................................................................... 3-3

3.2 Grouping Data ................................................................................................................. 3-4

Demonstration: Grouping Data .............................................................................................. 3-6

3.3 Table Lookups ............................................................................................................... 3-10

Demonstration: Table Lookups ............................................................................................ 3-13

3.4 Formats for Display ...................................................................................................... 3-15

Demonstration: Using Formats for Display .......................................................................... 3-20

Page 38: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-2 Chapter 3 Format Uses

Page 39: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.1 Introduction 3-3

3.1 Introduction

3

Objectives Use formats to group data.

Use formats to look up data.

Use formats to display data.

3

Page 40: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-4 Chapter 3 Format Uses

3.2 Grouping Data

5

Grouping Data in ProceduresProcedures that group data can use the formatted value to create reports:

PROC FREQ

PROC MEANS

PROC GCHART

5

6

Grouping Data in the DATA StepYou can use the GROUPFORMAT option in the DATA step with some cases of BY-group processing to use the formatted values, not the stored values.

General form of the GROUPFORMAT option:

6

BY GROUPFORMAT variable-name <NOTSORTED>;

Page 41: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.2 Grouping Data 3-5

7

Tips for Using the GROUPFORMAT OptionThe GROUPFORMAT option

is available only in the DATA step

is useful when you define formats for grouped data

enables the DATA step to process the same groups of data as a summary procedure or with PROC REPORT.

7

8

Advantages of GROUPFORMATThe GROUPFORMAT option

can be used to create ordered/grouped reports without sorting the data

frequently eliminates the need for another step.

8

Page 42: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-6 Chapter 3 Format Uses

Grouping Data

/* *************************************************** */ /* Program: f3d1.sas */ /* *************************************************** */ /* This program demonstrates how to use formats to */ /* group data. */ /* *************************************************** */ /* Run proc freq twice: without a grouping format and */ /* with a grouping format. */; proc freq data=ia.crew; tables hiredate; title 'FREQ without format'; run; proc freq data=ia.crew; tables hiredate; format hiredate year4.; title 'FREQ with format'; run; /* Create a user-defined grouping format. */ proc format; value $emp 'FLTAT1'-'FLTAT3'='Flight Attendant' 'PILOT1'-'PILOT3'='Pilot'; run; /* Run proc means twice: without the grouping format and */ /* with the grouping format. */; proc means data=ia.crew; class jobcode; var salary; title 'MEANS without format'; run; proc means data=ia.crew; class jobcode; format jobcode $emp.; var salary; title 'MEANS with format'; run;

(Continued on the next page.)

Page 43: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.2 Grouping Data 3-7

/* Run PROC TABULATE twice: without grouping formats and */ /* with grouping formats. */; proc tabulate data=ia.crew format=9.; class jobcode hiredate; tables hiredate, jobcode; title 'TABULATE Without Formats'; run; proc tabulate data=ia.crew format=9.; class jobcode hiredate; tables hiredate, jobcode; format jobcode $emp. hiredate year4.; title 'TABULATE With Formats'; run; /* Run proc gchart twice: without grouping formats and */ /* with grouping formats and DISCRETE option. */; goptions reset=pattern; proc gchart data=ia.crew; vbar jobcode hiredate; title 'GCHART without format'; run; vbar jobcode hiredate / discrete; format jobcode $emp. hiredate year4.; title 'GCHART with format and DISCRETE'; run; quit; ** Sort the data by date.; proc sort data=ia.crew out=sortedbydate; by hiredate; run; ** Create a variable containing year -- extra pass of the data.; data sortedbyyear; set sortedbydate; year=year(hiredate); run; data firsthired; set sortedbyyear; by year; if first.year; run; proc print data=firsthired; title 'First Employee Hired in Each Year'; run;

Page 44: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-8 Chapter 3 Format Uses

** Use the groupformat option to group by year.; data firsthired; set sortedbydate; by groupformat hiredate; format hiredate year4.; if first.hiredate; run; proc print data=firsthired; format hiredate date9.; title 'First Employee Hired in Each Year'; run;

Page 45: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.2 Grouping Data 3-9

Partial Output

Page 46: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-10 Chapter 3 Format Uses

3.3 Table Lookups

11

Lookup ValuesYou can use formats for table lookups when you want to lookup one value.

For example, you might have a model number stored with your data, but you want to include the model type.

11

12

Using the FORMAT ProcedureYou create the format for the lookup.

12

continued...

proc format library = ia;value model

1001 = 'JetCruise LF5000'1002 = 'JetCruise LF5100'1003 = 'JetCruise LF5200'...1010 = 'JetCruise MF6000'1011 = 'JetCruise SF1000'1012 = 'JetCruise SF3000'1013 = 'JetCruise SF7000';

run;

Page 47: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.3 Table Lookups 3-11

13

Using the FORMAT ProcedureUse the format in a PUT function to “look up” the values that you need.

13

options fmtsearch = (ia);

data models;set ia.aircraft;ModelType = put(ModelNum,Model.);

run;

14

Using the FORMAT ProcedureUse the format in a FORMAT statement to “look up” the values that you need:

14

options fmtsearch=(ia);

proc print data=ia.aircraft;format ModelNum Model.;

run;

Page 48: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-12 Chapter 3 Format Uses

15

Using the FORMAT ProcedureUse PROC FORMAT in the following situations:

There is a low to a medium number of values.

The lookup values are not stable.

The values are used in many programs.

15

Page 49: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.3 Table Lookups 3-13

Table Lookups

/* *************************************************** */ /* Program: f3d2.sas */ /* *************************************************** */ /* Use a format to look up values. */ /* *************************************************** */ ** Define a format to look up or validate data. ; proc format; value Model 1002='JetCruise LF8100' 1003='JetCruise LF5100' 1004='JetCruise LF5200' 1010='JetCruise MF2100' 1011='JetCruise MF4000' 1022='JetCruise SF1000' other='**invalid**'; run; ** Use a format to look up values in a data step.; data Models; set ia.aircraft; Model=put(Mnum,model.); run; proc print data=Models label; title 'All Models'; run; ** Use a format to look up values in a proc step.; proc print data=ia.aircraft label; format Mnum model.; where put(Mnum,model.) like '%MF%'; title 'MF Models'; run; proc print data=ia.aircraft label; where put(Mnum,model.) contains 'invalid'; title 'Invalid Models'; run;

Page 50: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-14 Chapter 3 Format Uses

Partial Output

Page 51: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.4 Formats for Display 3-15

3.4 Formats for Display

18

Formats for DisplayFormats are most obviously used for display, but various options can increase their usability.

FUZZ, NOTSORTED, MULTILABEL

Nesting formats

Used for colors or trafficlighting

18

19

Format OptionsOptions can be used in PROC FORMAT to modify the format’s structure.

FUZZ

NOTSORTED

MULTILABEL

19

Page 52: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-16 Chapter 3 Format Uses

20

Format Options - Fuzzy RangesFUZZ option

Use it to map a value if it is “close enough.”

The default fuzz value is 1E(-12).

20

21

Format Options - NOTSORTEDNOTSORTED Option

This option stores the format in the order in the VALUE statement.

Use the option to do the following:

– Save processing time

– Preserve the order in which you define ranges

Use the option with the PRELOADFMT option and ORDER=DATA to maintain the order in certain procedures.

21

Use NOTSORTED when the following conditions exist:

• You know the likelihood of certain ranges occurring, and you want your informat or format to search those ranges first to save processing time.

• You want to preserve the order in which you define ranges when you print a description of the informat or format using the FMTLIB option.

• You want to preserve the order in which you define ranges when you use the ORDER=DATA option and the PRELOADFMT option to analyze class variables in PROC MEANS, PROC SUMMARY, or PROC TABULATE.

Page 53: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.4 Formats for Display 3-17

22

Creating Overlapping RangesTo create overlapping ranges, use the MULTILABEL option in the VALUE statement in PROC FORMAT:

Create a report with any procedure that supports the MLF option.

PROC TABULATE

PROC MEANS

PROC SUMMARY

22

VALUE <$>fmtname <(MULTILABEL)> ...

23

Nested FormatsCreate a format that maps value ranges to existing formats. Use this format in the following situations:

A modular approach is needed for ease of maintenance.

One format is not desirable across the entire range.

23

Page 54: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-18 Chapter 3 Format Uses

24

Using Formats to Apply ColorsYou can use the FORMAT procedure to apply different colors to each of the data values. After you create a format, use the STYLE= option to apply that format to the foreground or the background of the column.

24

PROC FORMAT;VALUE $fmtname 'data-value-1'='color-1'

'data-value-2'='color-2'...

'data-value-n'='color-n';

25

Trafficlighting with PROC TABULATEYou can use trafficlighting to highlight specific information about a report.

To add cell trafficlighting, perform the following steps:

Create a user-defined format.

On the column you want to highlight, use the following:

25

*{S={BACKGROUND=format.}}

Page 55: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.4 Formats for Display 3-19

26

Trafficlighting with PROC REPORTYou can use trafficlighting to highlight specific information about a report.

To trafficlight with PROC REPORT, use a COMPUTE block for the variable on which you want to trafficlight.

26

Page 56: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-20 Chapter 3 Format Uses

Using Formats for Display

/* *************************************************** */ /* Program: f3d3.sas */ /* *************************************************** */ /* This program demonstrates how to use options to */ /* modify the behavior of formats. */ /* *************************************************** */

** Use the NOTSORTED option to control display order. ; proc format; value $emp (notsorted) 'PILOT1'-'PILOT3'='Pilot' 'MECH01'-'MECH03'='Mechanics' 'FLTAT1'-'FLTAT3'='Flight Attendant'; run;

** The preloadfmt option along with order=data ; ** results in the table being drawn in the order ; ** in which the format items are defined. ; ** The completetypes option forces all format ; ** items to appear in the output. ; proc means data=ia.crew order=data completetypes; class jobcode / preloadfmt; var salary; title 'MEANS with PRELOADFMT'; format jobcode $emp.; run;

** Use the multilabel option to create a ; ** format with overlapping ranges. ; proc format; value hires (multilabel) low -< '01jan1985'd = 'First Group' '01jan1985'd -< '01jan1990'd = 'Second Group' '01jan1990'd - high = 'Third Group' '01jan1980'd -< '01jan1981'd = '1980' '01jan1981'd -< '01jan1982'd = '1981' '01jan1982'd -< '01jan1983'd = '1982' '01jan1983'd -< '01jan1984'd = '1983' '01jan1984'd -< '01jan1985'd = '1984' '01jan1985'd -< '01jan1986'd = '1985' '01jan1986'd -< '01jan1987'd = '1986' '01jan1987'd -< '01jan1988'd = '1987' '01jan1988'd -< '01jan1989'd = '1988' '01jan1989'd -< '01jan1990'd = '1989' '01jan1990'd -< '01jan1991'd = '1990' '01jan1991'd -< '01jan1992'd = '1991' '01jan1992'd -< '01jan1993'd = '1992' '01jan1993'd -< '01jan1994'd = '1993' '01jan1994'd -< '01jan1995'd = '1994'; run;

(Continued on the next page.)

Page 57: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.4 Formats for Display 3-21

** Add the MLF option in the CLASS statement to use the; ** multilabel format.; proc means data=ia.crew; var salary; class hiredate / mlf; format hiredate hires.; title 'MEANS with MLF (multilabel format)'; run; ** Use nested formats to combine user-defined and SAS formats.; proc format; value benefit low-'31dec89'd=[worddate20.] '01jan90'd-high=' ** Not Eligible **' ; run; proc print data=ia.crew; var firstname lastname hiredate; format hiredate benefit.; title 'Nested formats'; run; ** Use formats to do trafficlighting.; proc format; value fore low-30000 = 'derp' 30000<-40000 = 'white' 40000<-42000 = 'white' 42000<-high = 'blue' other = 'white'; value back low-30000 = 'vpap' 30000<-40000 = 'vlib' 40000<-42000 = 'vipk' 42000<-high = 'vpab' other = 'white'; run;

(Continued on the next page.)

Page 58: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-22 Chapter 3 Format Uses

ods listing close; ods html file='test.html' style=statDoc; proc tabulate data=ia.crew f=dollar8.; title 'Traffic Lighting in PROC TABULATE'; where JobCode contains 'FLTAT'; var Salary; class Location JobCode; table Location*Salary*(min mean max)* {s={background=back. foreground=fore.}}, JobCode / rts=20 box={label='Flight Attendants'}; keylabel mean='Average' max='Maximum' min='Minimum'; label JobCode='Code' Location='Location' Salary='Salary'; run; proc report data=ia.crew nowd; title 'Traffic Lighting in PROC REPORT'; columns Location Jobcode firstname lastname name salary ; define location / order; define jobcode / order order=formatted f=$emp.; define firstname / noprint; define lastname / noprint; define name / computed 'Employee'; define salary / f=dollar8. style(column)={background=back. foreground=fore.}; compute name / char length=20; name=trim(firstname)||' '||lastname; endcomp; run; ods html close; ods listing;

Page 59: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3.4 Formats for Display 3-23

Partial Output

Page 60: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

3-24 Chapter 3 Format Uses

Page 61: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

Chapter 4 New in SAS® 9.3

4.1 Introduction ..................................................................................................................... 4-3

4.2 Viewing Formats and Using Functions ........................................................................ 4-4

Demonstration: New Features in SAS 9.3 ............................................................................. 4-6

Page 62: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

4-2 Chapter 4 New in SAS® 9.3

Page 63: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

4.1 Introduction 4-3

4.1 Introduction

3

Objectives View formats in the Explorer window.

Use functions to create formats.

3

Page 64: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

4-4 Chapter 4 New in SAS® 9.3

4.2 Viewing Formats and Using Functions

5

Viewing FormatsIn the current release of SAS it is possible to view formats by clicking on the name of the format in the Explorer window.

5

6

Viewing FormatsThis action causes the format definition to be displayed in the Results Viewer.

6

Page 65: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

4.2 Viewing Formats and Using Functions 4-5

7

Using Functions to Define FormatsIt is now possible to use a function to define a format.

General form of the VALUE statement:

7

VALUE $format name OTHER=[function name()];

8

Using Functions to Define FormatsIt is now possible to use a function to define a format.

Example:

8

proc format;value $stn other=[stnamel()];

run;

Page 66: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

4-6 Chapter 4 New in SAS® 9.3

New Features in SAS 9.3

Program f4d1.sas

/* *************************************************** */ /* Program: f4d1.sas */ /* *************************************************** */ /* This program demonstrates the ability to use */ /* functions in formats - new in SAS9.3. */ /* *************************************************** */ proc format; value $stn other=[stnamel()]; run; proc report data=ia.summary nowd; title 'Displaying State Names Using a Format Based on a Function'; column stcode stcode=name; define stcode / "Original Value"; define name / "Value with Format" format=$stn30.; run; /* 1. Use the FCMP procedure to create the function. 2. Use the OPTIONS statement to make the function available to SAS by specifying the location of the function in the CMPLIB= system option. 3. Use the FORMAT procedure to create a new format. 4. Use the new format in your SAS program. */ /* 1. Create a function that creates the value Qx from a formatted value. */ proc fcmp outlib=work.functions.smd; function qfmt(date) $; length qnum $4; qnum=put(date,yyq4.); if substr(qnum,3,1)='Q' then return(substr(qnum,3,2)); else return(qnum); endsub; run; /* 2. Make the function available to SAS. */ options cmplib=(work.functions);

(Continued on the next page.)

Page 67: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

4.2 Viewing Formats and Using Functions 4-7

/* 3. Create a format using the function created by the FCMP procedure. */ proc format; value qfmt other=[qfmt()]; run; /* 4. Use the format in a SAS program. */ data djia2009; input closeDate date7. close; datalines; 01jan09 800.86 02feb09 7062.93 02mar09 7608.92 01apr09 8168.12 01may09 8500.33 01jun09 8447.00 01jul09 9171.61 03aug09 9496.28 01sep09 9712.28 01oct09 9712.73 02nov09 10344.84 02dec09 10428.05 run; proc print data=djia2009; title 'Displaying Quarters Using a Format Based on a User-Defined Function'; format closedate qfmt. close dollar9.; run;

Page 68: SAS Formats and the FORMAT Procedure · 2-4 Chapter 2 Format Utilities 2.2 Creating Permanent Formats 5 General Form of a PROC FORMAT Step To create a permanent format, add the LIBRARY=

4-8 Chapter 4 New in SAS® 9.3

Partial Output


Recommended