SAS® Viya™ 3.1 Formats and Informats: Reference
Total Page:16
File Type:pdf, Size:1020Kb
SAS® Viya™ 3.1 Formats and Informats: Reference SAS® Documentation The correct bibliographic citation for this manual is as follows: SAS Institute Inc. 2016. SAS® Viya™ 3.1 Formats and Informats: Reference. Cary, NC: SAS Institute Inc. SAS® Viya™ 3.1 Formats and Informats: Reference Copyright © 2016, SAS Institute Inc., Cary, NC, USA All Rights Reserved. Produced in the United States of America. For a hard copy book: 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. For a web download or e-book: Your use of this publication shall be governed by the terms established by the vendor at the time you acquire this publication. The scanning, uploading, and distribution of this book via the Internet or any other means without the permission of the publisher is illegal and punishable by law. Please purchase only authorized electronic editions and do not participate in or encourage electronic piracy of copyrighted materials. Your support of others' rights is appreciated. U.S. Government License Rights; Restricted Rights: The Software and its documentation is commercial computer software developed at private expense and is provided with RESTRICTED RIGHTS to the United States Government. Use, duplication, or disclosure of the Software by the United States Government is subject to the license terms of this Agreement pursuant to, as applicable, FAR 12.212, DFAR 227.7202-1(a), DFAR 227.7202-3(a), and DFAR 227.7202-4, and, to the extent required under U.S. federal law, the minimum restricted rights as set out in FAR 52.227-19 (DEC 2007). If FAR 52.227-19 is applicable, this provision serves as notice under clause (c) thereof and no other notice is required to be affixed to the Software or documentation. The Government’s rights in Software and documentation shall be only those set forth in this Agreement. SAS Institute Inc., SAS Campus Drive, Cary, NC 27513-2414 September 2016 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. 3.1-P1:leforinforref Contents PART 1 SAS Formats 1 Chapter 1 • Overview of SAS Formats . 3 Definition of Formats . 4 Syntax . 4 Using Formats . 5 Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms . 8 Data Conversions and Encodings . 9 Working with Packed Decimal and Zoned Decimal Data . 10 Working with Dates and Times By Using the ISO 8601 Basic and Extended Notations . 14 Chapter 2 • SAS Formats Documented in Other Publications . 31 Documentation for Additional Formats . 31 Chapter 3 • Dictionary of SAS Formats . 33 Formats by Category . 37 Dictionary . 61 PART 2 SAS Informats 325 Chapter 4 • Overview of SAS Informats . 327 Definition of Informats . 327 Syntax . 328 Using Informats . 328 Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms . 331 Working with Packed Decimal and Zoned Decimal Data . 333 Reading Dates and Times By Using the ISO 860 Basic and Extended Notations . 337 Chapter 5 • SAS Informats Documented in Other Publications . 345 Documentation for Additional Informats . 345 Chapter 6 • Dictionary of SAS Informats . 347 Informats by Category . 349 Dictionary . 360 Recommended Reading . 505 Index . 507 iv Contents 1 Part 1 SAS Formats Chapter 1 Overview of SAS Formats . 3 Chapter 2 SAS Formats Documented in Other Publications . 31 Chapter 3 Dictionary of SAS Formats . 33 2 3 Chapter 1 Overview of SAS Formats Definition of Formats . 4 Syntax . 4 Using Formats . 5 Ways to Specify Formats . 5 Permanent versus Temporary Association . 6 User-Defined Formats . 7 Restrictions on Formatting Dates . 7 Byte Ordering for Integer Binary Data on Big Endian and Little Endian Platforms . 8 Definitions . 8 How Bytes Are Ordered Differently . 8 Writing Data Generated on Big Endian or Little Endian Platforms . 8 Integer Binary Notation and Different Programming Languages . 9 Data Conversions and Encodings . 9 Working with Packed Decimal and Zoned Decimal Data . 10 Definitions . 10 Types of Data . 11 Platforms That Support Packed Decimal and Zoned Decimal Data . 12 Languages That Support Packed Decimal and Zoned Decimal Data . 12 Summary of Packed Decimal and Zoned Decimal Formats and Informats . 13 Working with Dates and Times By Using the ISO 8601 Basic and Extended Notations . 14 ISO 8601 Formatting Symbols . 14 Definitions . 15 About Dates and Times That Use the ISO 8601 Basic and Extended Notations . 16 Basic ISO 8601 Date, Time, and Datetime Values . 17 Extended ISO 8601 Date, Time, and Datetime Values . 18 Tips for Remembering UTC Formats That Use Time Zone Offsets . 19 Examples of Reading and Writing Basic and Extended ISO 8601 Date, Time, and Datetime Values . 20 Writing ISO 8601 Duration, Datetime, and Interval Values . 25 4 Chapter 1 • Overview of SAS Formats Definition of Formats A format is a type of SAS language element that applies a pattern to or executes instructions for a data value to be displayed or written as output. Types of formats correspond to the type of data: numeric, character, date, time, or timestamp. The ability to create user-defined formats is also supported. Examples of SAS formats are BINARY, DATE, and WORDS. For example, the WORDS22. format, which converts numeric values to their equivalent in words, writes the numeric value 692 as six hundred ninety-two. Syntax SAS formats have the following form: <$>format<w>.<d> $ indicates a character format. Its absence indicates a numeric format. format names the format. The format is a SAS format or a user-defined format that was previously defined with the VALUE statement in PROC FORMAT. See For information about user-defined formats, see “FORMAT” in SAS Viya Data Management and Utility Procedures Guide. w specifies the format width, which for most formats is the number of columns in the output data. d specifies an optional decimal scaling factor in the numeric formats. Formats contain a period (.) as a part of the name. If you omit the w and d values from the format, SAS uses default values. The d value that you specify with a format tells SAS to display that many decimal places. Formats never change or truncate the internally stored data values. For example, in DOLLAR10.2, the w value of 10 specifies a maximum of 10 columns for the value. The d value of 2 specifies that two of these columns are for the decimal part of the value, which leaves eight columns for the remaining characters in the value. The remaining columns include the decimal point, the remaining numeric value, a minus sign if the value is negative, the dollar sign, and commas, if any. If the format width is too narrow to represent a value, SAS tries to squeeze the value into the space available. Character formats truncate values on the right. Numeric formats sometimes revert to the BESTw.d format. SAS prints asterisks if you do not specify an adequate width. In the following example, the result is x=**. x=123; put x= 2.; Using Formats 5 If you use an incompatible format, such as a numeric format to write character values, SAS first attempts to use an analogous format of the other type. If this attempt fails, an error message that describes the problem is displayed in the SAS log. When the value of d is greater than 15, the precision of the decimal value after the 15th significant digit might not be accurate. Using Formats Ways to Specify Formats About Specifying Formats You can use formats in these ways: • in a PUT statement • with the PUT, PUTC, or PUTN functions • with the %SYSFUNC macro function • in a FORMAT statement in a DATA step or a PROC step • in an ATTRIB statement in a DATA step or a PROC step PUT Statement The PUT statement with a format after the variable name uses a format to write data values in a DATA step. For example, this PUT statement uses the DOLLARw.d format to write the numeric value for AMOUNT as a dollar amount: amount=1145.32; put amount dollar10.2; The DOLLARw.d format in the PUT statement produces this result: $1,145.32 For more information, see “PUT Statement” in SAS Viya Statements: Reference. PUT Function The PUT function converts a numeric variable, a character variable, or a constant by using any valid format and then returns the resulting character value. For example, the following statement converts the value of a numeric variable to a two-character hexadecimal representation: num=15; char=put(num,hex2.);.