28
Copyright © 2012, SAS Institute Inc. All rights reserved. SAS Functions Old and New Randy Betancourt

SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Embed Size (px)

Citation preview

Page 1: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

SAS Functions Old and NewRandy Betancourt

Page 2: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Types of Functions OVERVIEW

Character Numeric Date and Time Macro State and Zip Code Special SAS Data set I/O External File I/O Variable Information

Page 3: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Changes and Enhancements OVERVIEW

In Release 9.2• Added 40+ new functions. • TRANSTRN removes or replaces all occurrences of a

substring in a character string Moved numerous SAS/ETS and Risk Dimensions functions into

Base SAS• INTFMT returns a recommended format, given a date, time,

or datetime interval Moved High Performance Forecasting functions into Base SAS

• HOLIDAY returns the date of the specified holiday for the specified year

Enhancements to numerous functions and CALL Routines

Page 4: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Changes and Enhancements OVERVIEW

In Release 9.3• Added new functions • MVALID checks the validity of a character string for use as

a SAS member name Enhancements to existing functions and CALL Routines SAS Documentation Change

• The SAS Language Reference: Dictionary is divided into 7 documents

• SAS Functions and CALL Routines: Reference

Page 5: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Length Assignment Rules Character Strings

Character variable lengths are set at Compile-time Context determines how lengths are set: Explicitly

INFORMATS on INFILE/INPUT LENGTH statement ATTRIB statement DBSTYPE= data set option (SAS/Access)

Implicitly On initial assignment Metadata exchange, e.g. default mappings with

SAS/Access

Page 6: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Comparisons Character Strings

Page 7: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Comparisons Character Strings

Page 8: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

LENGTH & LENGTHC Character Strings

Page 9: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

ANYxxx and NOTxxxFunctions Character Strings

Page 10: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

SUBSTR and INPUT Functions Character Strings

Page 11: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

SUBSTR (left of =) and PUT Functions Character Strings

Page 12: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

CAT, CATS, and CATX Functions Character Strings

Page 13: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

PUT and INPUT Functions Character Strings

Page 14: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

SAS Macro Functions Character Strings

Page 15: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

PERL Regular Expressions Character Strings

Page 16: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

PROC FCMP User-defined Functions

Page 17: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

SAS Date Time Processing

SAS Date values represent the number of days between January 1, 1960 and a specified date.

SAS Time values represent the number of seconds since midnight of the current day. SAS time values are between 0 and 86400.

SAS Datetime values represent the number of seconds between January 1, 1960 and an hour/minute/second within a specified date and time.

These values are stored as numbers and can be read with SAS informats and displayed with SAS formats

Page 18: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Date Informats SAS Date Processing

Page 19: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

YEARCUTOFF Behavior SAS Date Processing

Page 20: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

MDY, MONTH, DAY Functions SAS Date Processing

Page 21: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

INTCK and TODAY Functions SAS Date Processing

Page 22: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

INTNX Function SAS Date Processing for Finding First and Last of Month

Page 23: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

INTNX Function SAS Date Processing for Finding First and Last of Month (Business Week)

Page 24: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

INTNX Function Finding First and Last of Month for Business Week to Build a Format

Page 25: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

PROC FMTLIB Validating Formats

Page 26: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

INTNX Function Finding First and Last of Month for Business Week to Build a Format

Page 27: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

Best Practices Ensuring Date Integrity

Store dates as SAS date values, not as simple numeric or characters

Explicitly set YEARCUTOFF= when using 2-digit SAS date values

2-digit years spanning more than 100 years must either use 4-digit years in the data, or handled with conditional logic

Ensure output data sets represent dates as SAS date values

Examine output closely to ensure formats and informatsare producing the intended results

Page 28: SAS Functions Old and New - denversug.orgdenversug.org/presentations/2012CODay/SAS_Functions_Date_Empha… · SAS Functions), by Ron Cody SAS Functions Old and New, by Ron Coleman,

Copyr igh t © 2012, SAS Ins t i tu te Inc . A l l r igh ts reserved.

An Introduction to SAS Character Functions (Including New SAS Functions), by Ron Cody

SAS Functions Old and New, by Ron Coleman, Internal SAS Presentation

SAS Date/Time Processing, by Cynthia Johnson, Internal SAS Presentation

SAS 9.3 Functions and CALL Routines: Reference at: support.sas.com

References