36
Rt f th Cd Rt f th Cd Return of the Codes: SAS® Windows® and Yours Return of the Codes: SAS® Windows® and Yours SAS ®, Windows ®, and Your s SAS ®, Windows ®, and Your s Mark Tabladillo Ph.D. MarkTab Consulting Mark Tabladillo Ph.D. MarkTab Consulting Copyright © 2007, SAS Institute Inc. All rights reserved. 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. Microsoft is a registered trademark of Microsoft Corporation in the United States and other countries. MarkTab Consulting Associate Faculty, University of Phoenix MarkTab Consulting Associate Faculty, University of Phoenix

Return of the Codes -- SAS', Windows' and Your's

Embed Size (px)

DESCRIPTION

Robust applications engage in the give-and-take discussion between commands and return codes. This presentation encourages applications developers to implement comprehensive return code processing. This paper presents three distinct categories. First, we consider return codes from SAS®. Second, we consider return codes from the Windows® (as an example operating system). Third, we discuss development principles for proactively writing your own return messages. The examples draw from SAS/AF® and Windows®, and affect all SAS applications development (including robust SAS Macro development). This paper introduces the rich conversation an application can and should have with its environment. Special attention focuses on error messages and recovering gracefully from unexpected or unintentional results.

Citation preview

Page 1: Return of the Codes -- SAS', Windows' and Your's

R t f th C d R t f th C d Return of the Codes: SAS’® Windows’® and Your’sReturn of the Codes: SAS’® Windows’® and Your’sSAS ®, Windows ®, and Your sSAS ®, Windows ®, and Your s

Mark Tabladillo Ph.D.MarkTab ConsultingMark Tabladillo Ph.D.MarkTab Consulting

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.Microsoft is a registered trademark of Microsoft Corporation in the United States and other countries.

MarkTab ConsultingAssociate Faculty, University of PhoenixMarkTab ConsultingAssociate Faculty, University of Phoenix

Page 2: Return of the Codes -- SAS', Windows' and Your's

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 3: Return of the Codes -- SAS', Windows' and Your's

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 4: Return of the Codes -- SAS', Windows' and Your's

C i t Communicate Better!

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 5: Return of the Codes -- SAS', Windows' and Your's

Introduction

Applications have an ongoing conversation• Users, Databases, Other Applications

Return code represents many of these often numeric messages

E t d ib th lEvent messages describe the general communication category

Error messages are a special caseError messages are a special case

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 6: Return of the Codes -- SAS', Windows' and Your's

Purpose

Describe how three innovative messaging sources support robust SAS applications developmentdevelopment

1. SAS (the programming language)2. Windows (the operating system)3. Yours (customized)

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 7: Return of the Codes -- SAS', Windows' and Your's

SAS Windows

Who’s Talking?

WE! ( d )WE! (you and me)

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 8: Return of the Codes -- SAS', Windows' and Your's

SAS 101: Print a Dataset

options pagesize=60 linesize=80 pageno=1 nodate;libname mylib 'permanent-data-library';libname mylib permanent data library ;data mylib.internationaltours;

infile 'input-file';input Country $ Nights AirCost LandCost Vendor $;p y $ g $;

proc print data = mylib.internationaltours;title 'Data Set MYLIB.INTERNATIONALTOURS';

run;

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 9: Return of the Codes -- SAS', Windows' and Your's

SAS 101: Print a DatasetSAS 201: How do you know it works?

options pagesize=60 linesize=80 pageno=1 nodate;libname mylib 'permanent-data-library';libname mylib permanent data library ;data mylib.internationaltours;

infile 'input-file';input Country $ Nights AirCost LandCost Vendor $;p y $ g $;

proc print data = mylib.internationaltours;title 'Data Set MYLIB.INTERNATIONALTOURS';

run;

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 10: Return of the Codes -- SAS', Windows' and Your's

SAS 101: Print a DatasetSAS 201: How do you know it works?SAS 301: What could go wrong?options pagesize=60 linesize=80 pageno=1 nodate;libname mylib 'permanent-data-library';

SAS 301: What could go wrong?

libname mylib permanent data library ;data mylib.internationaltours;

infile 'input-file';input Country $ Nights AirCost LandCost Vendor $;p y $ g $;

proc print data = mylib.internationaltours;title 'Data Set MYLIB.INTERNATIONALTOURS';

run;

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 11: Return of the Codes -- SAS', Windows' and Your's

C O S S®SASSAS

Category One: SAS®

SAS provides efficient event messaging using seven features:

1 S t O ti1. System Options2. Automatic Macro Variables3. ARM Macros4. Functions5. Call MODULE Routine6 PUT Statement6. PUT Statement7. SCL Event Classes

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 12: Return of the Codes -- SAS', Windows' and Your's

S S S OSASSAS

SAS: System Options

System options are instructions that affect the SAS session

Querying system options can be done through dictionary tables

Use SCL commands OPTGETC OPTGETNUse SCL commands OPTGETC, OPTGETN, OPTSETC, and OPTSETN

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 13: Return of the Codes -- SAS', Windows' and Your's

S S S OSASSAS

SAS: System Option Examples

DSNFERR – Controls how SAS responds when a SAS dataset is not found

ERRORCHECK – controls error handling

MPRINT – Displays SAS statements that are generated by macro executiongenerated by macro execution

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 14: Return of the Codes -- SAS', Windows' and Your's

S SSASSAS

SAS: Automatic Macro Variables

The SAS macro processor creates automatic macro variables

Automatic macro variables complement system options by allowing SAS to report current state

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 15: Return of the Codes -- SAS', Windows' and Your's

S SSASSAS

SAS: Automatic Macro Variables

SYSRC (read and write) – various system-related return codes

SYSPROCESSID – the process ID of the current SAS process

SYSPROCESSNAME the process name of theSYSPROCESSNAME – the process name of the current SAS process

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 16: Return of the Codes -- SAS', Windows' and Your's

S SSASSAS

SAS: ARM Macros

ARM (Automatic Response Measurement) Macros provide a way to measure the performance of applications as they executeperformance of applications as they execute

The macros are lightweight and are designed to run outside the DATA step and PROC pstatements

The ARM API provides an interface to retrieve performance informationperformance information

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 17: Return of the Codes -- SAS', Windows' and Your's

S SSASSAS

SAS: Functions

A function performs a computation or system manipulation on arguments and returns a value

In addition to base SAS functions, SCL provides other functions which have return codes

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 18: Return of the Codes -- SAS', Windows' and Your's

S SSASSAS

SAS: Function Examples

SYSRC – returns a system error number

SYSGET – returns the value of the specified poperating environment variable

SYSTEM – issues an operating system environment command during a SAS sessionenvironment command during a SAS session and returns the system return code

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 19: Return of the Codes -- SAS', Windows' and Your's

S S CSASSAS

SAS: CALL Module Routine

CALL Module “calls the external routine without any return code”

CALL Module “calls the external routine without an explicit SAS return code”

Allows extended reach in Windows and UnixAllows extended reach in Windows and Unix

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 20: Return of the Codes -- SAS', Windows' and Your's

S S SSASSAS

SAS: PUT Statement

The PUT statement allows for general reporting to the LOG or any ODS destination

Allows for documenting and reporting return codes to users

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 21: Return of the Codes -- SAS', Windows' and Your's

S S SC CSASSAS

SAS: SCL Event Classes

Events allow for communication among visual and non-visual classes

The SCL Exception class provides a framework for throwing exceptions (distinct from regular events))

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 22: Return of the Codes -- SAS', Windows' and Your's

C ®WindowsWindows

Category Two: Windows®

Windows provides SAS efficient event messaging using four features:1 SAS S t O ti f Wi d1.SAS System Options for Windows2.SAS Automatic Macro Variables for Windows3.SAS Functions and CALL Routines for Windows4.Windows System Error Codes

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 23: Return of the Codes -- SAS', Windows' and Your's

S SWindowsWindows

Windows: SAS Features

SAS has separate documentation for each operating system

SAS running on Windows has extended capabilities for• System optionsSystem options• Automatic macro variables• Functions and CALL routines

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 24: Return of the Codes -- SAS', Windows' and Your's

32 S CWindowsWindows

Windows: Windows 32 API System Error Codes

The CALL module routine can access the Windows 32 API DLLs

The full list of Windows error codes can be returned to SAS

The gateway can also provide interactiveThe gateway can also provide interactive communication with Windows

Supported in 64-bit Vista and Server 2008Supported in 64 bit Vista and Server 2008

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 25: Return of the Codes -- SAS', Windows' and Your's

CYoursYours

Category Three: Yours

We can create event messaging systems that emulate what SAS and Windows provide

Three distinct outputs1. Receive no response2 Receive a response sometimes (incomplete)2. Receive a response sometimes (incomplete)3. Always receive a response

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 26: Return of the Codes -- SAS', Windows' and Your's

YoursYoursCategory Three: YoursCategory DescriptionCategory DescriptionApplication Options

Similar to SAS system options, application options are variables declared either globally

or locally for an application, and allow for return code processing to be controlled fromreturn code processing to be controlled from

a higher level. The variables could be stored in application datasets, similar to the

read only dictionary tablesread-only dictionary tables.

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 27: Return of the Codes -- SAS', Windows' and Your's

YoursYoursCategory Three: YoursCategory DescriptionCategory DescriptionApplication Macro Variables Similar to SAS automatic macro variables,

th li ti i bl ( l b lthe application macro variables (global or local) provide the ability to keep the state at a specific point. Information stored could be p p

character or text (though macro variables always store information as text).

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 28: Return of the Codes -- SAS', Windows' and Your's

YoursYoursCategory Three: YoursCategory DescriptionCategory DescriptionApplication Macros Similar to SAS ARM Macros, the application

h it t it dcan have its own macros to monitor and measure performance. These customized

macros could extend the capabilities of ARM macros, providing the application with

robust reporting on performance. Developing these macros separately fromDeveloping these macros separately from other macros allows them to be used in

future applications.

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 29: Return of the Codes -- SAS', Windows' and Your's

YoursYoursCategory Three: YoursCategory DescriptionCategory DescriptionFunctions Similar to SAS functions, applications can

d fi th d i SCL Th th ddefine methods in SCL. These methods can provide a return code, and could extend or incorporate what SAS natively provides p y pfor return code processing. Encapsulating these methods individually, or as a group

(creating a class or classes using SAS/AF)(creating a class or classes using SAS/AF) would allow these methods or classes to be

copied into future applications.

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 30: Return of the Codes -- SAS', Windows' and Your's

YoursYoursCategory Three: YoursCategory DescriptionCategory DescriptionCALL Module Routine

Similar to calling Windows DLLs, SAS li ti i i Wi d ld llapplications running in Windows could call

programmed .NET DLLs. These modules could have return codes and messages helping the application to become more

robust. Generically developed DLLs have the advantage of being used across manythe advantage of being used across many

custom applications.

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 31: Return of the Codes -- SAS', Windows' and Your's

YoursYoursCategory Three: YoursCategory DescriptionCategory DescriptionReporting Datasets and Forms Instead of simply using the PUT statement

t d i bl l t th lto send variable values to the log, an application could store the information in a dataset. Also, the application could have , pp

customized forms for reporting errors, including the option to send those reports as

an attachment or the body of an e-mailan attachment or the body of an e-mail.

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 32: Return of the Codes -- SAS', Windows' and Your's

YoursYoursCategory Three: YoursCategory DescriptionCategory DescriptionEvent Classes Create event classes which capture specific

t d t C t t i dreturn codes as events. Create customized SCL classes based on the SCL exception class; alternatively, use a language which ; y, g gcan produce a COM interface to work with

SAS to provide advanced error capabilities. Use event classes to communicate acrossUse event classes to communicate across

components and applications.

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 33: Return of the Codes -- SAS', Windows' and Your's

f CAdvice for Reusable CodeUse binary codes for success or failurey

Consider global enumeration storage to allow for named references to return code conditions

Use simple, reusable names for macros, functions, and classesUse simple, reusable names for macros, functions, and classes

Code for the complete set of possible conditions, not only the ones proven through experience

Optionally implement reporting to the SAS log or to an external event logOptionally implement reporting to the SAS log, or to an external event log (database or file)

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 34: Return of the Codes -- SAS', Windows' and Your's

CConclusion

Described how three innovative messaging sources support robust SAS applications developmentdevelopment

1. SAS (the programming language)2. Windows (the operating system)3. Your’s (customized)

Comprehensive return messaging defines robust applicationsrobust applications

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 35: Return of the Codes -- SAS', Windows' and Your's

C i t Communicate Better!

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.

Page 36: Return of the Codes -- SAS', Windows' and Your's

R t f th C d R t f th C d Return of the Codes: SAS’® Windows’® and Your’sReturn of the Codes: SAS’® Windows’® and Your’sSAS ®, Windows ®, and Your sSAS ®, Windows ®, and Your s

Mark Tabladillo Ph.D.MarkTab ConsultingMark Tabladillo Ph.D.MarkTab Consulting

Copyright © 2007, SAS Institute Inc. All rights reserved. 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.Microsoft is a registered trademark of Microsoft Corporation in the United States and other countries.

MarkTab ConsultingAssociate Faculty, University of PhoenixMarkTab ConsultingAssociate Faculty, University of Phoenix