50 base sas tips - lex jansen · title: automated scorecard application author: steve hanks created...

54
50 Base SAS Tips Steve Hanks

Upload: others

Post on 20-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

50 Base SAS Tips

Steve Hanks

Page 2: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 2 Copyright © 2003 Amadeus Software Limited

Tip 1 – Keep, Rename and then Where

Order of processing by SAS is, drop or

keep first then the rename and finally the

where clause.

Basically it’s in ALPHABETICAL order!

Page 3: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 3 Copyright © 2003 Amadeus Software Limited

Tip 2 – Use Keep and Drop for Efficiency

Page 4: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 4 Copyright © 2003 Amadeus Software Limited

Tip 3 – Be Consistent

Make life easy for those who have to read your

code by being consistent. Place statements like

label, length, format and retain together.

But keep in mind

• Same statements (eg length) need to be used

• Placement may effect variable order in data set

Page 5: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 5 Copyright © 2003 Amadeus Software Limited

Tip 4 – Keep b--a

Keeps the variables gender,

children and all variables

between. Uses the order of the

variables within the data set ie:

the LPDV.

Page 6: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 6 Copyright © 2003 Amadeus Software Limited

Tip 5 – Keep _numeric_

Keeps all the numeric variables

within the demog data set.

_character_ also works.

Page 7: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 7 Copyright © 2003 Amadeus Software Limited

Tip 6 – a=b=c=d?

If b=c and c=d then a=1;

Else a=0

If b=c=d then a=1;

Else a=0;

A=b=c=d;

Page 8: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 8 Copyright © 2003 Amadeus Software Limited

Tip 7 – Proc Sort – Option Noequals

More efficient because it does not

keep the order of other that a data

set is currently in with same sort

variables.

Page 9: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 9 Copyright © 2003 Amadeus Software Limited

8 – Sum Function

When adding a missing value sum treats

as 0, the + sign returns a missing value

Page 10: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 10 Copyright © 2003 Amadeus Software Limited

Tip 9 – Use SCL Functions in Base

You can use SCL functions in

BASE SAS either within a data

step or within macros using

%sysfunc

Page 11: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 11 Copyright © 2003 Amadeus Software Limited

Tip 10 – Mfile Option for Macros

Writes the base SAS code

generated by a macro to a external

file.

Page 12: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 12 Copyright © 2003 Amadeus Software Limited

Tip 11 – Use : As Wildcard

Selecting variables that start

with c, and observations

where the staffno begins

with 01

Page 13: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 13 Copyright © 2003 Amadeus Software Limited

Tip 12 – Scan Function

A=scan(textstring,-1)

From V8 onwards the second

parameter can be negative. In the

above example the last word is

selected.

Page 14: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 14 Copyright © 2003 Amadeus Software Limited

Tip 13 – Align with Put

The –C centres the result from the put

statement.

-L and –R are also available for left and right

Page 15: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 15 Copyright © 2003 Amadeus Software Limited

Tip 14 – Put and Input

Put, always returns a Character String

Input, always returns a Numeric Value

Page 16: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 16 Copyright © 2003 Amadeus Software Limited

Tip 15 – Formats to SAS Data Set

Page 17: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 17 Copyright © 2003 Amadeus Software Limited

Tip 16 – SAS Data Set to Format

Page 18: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 18 Copyright © 2003 Amadeus Software Limited

Tip 17 – HLO Values For Formats

HLO - character variable that contains range

information. Possible Values

H- range's ending value is HIGH

I - numeric informat range

L - range's starting value is LOW

N - format or informat has no ranges, including no

OTHER= range

O - range is OTHER

R - ROUND option is in effect

S - NOTSORTED option is in effect

Page 19: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 19 Copyright © 2003 Amadeus Software Limited

Tip 18 - Scanover

Page 20: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 20 Copyright © 2003 Amadeus Software Limited

Tip19 - Cards4

Page 21: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 21 Copyright © 2003 Amadeus Software Limited

Tip 20 – File Pipe

Page 22: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 22 Copyright © 2003 Amadeus Software Limited

Tip 21 – Compress Option

COMPRESS=YES | NO | CHAR | BINARY

Page 23: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 23 Copyright © 2003 Amadeus Software Limited

Tip 22 – User Libref

If you assign a libname with a libref of “user” the data sets

with a one level name will be saved here and not in

“work”.

Page 24: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 24 Copyright © 2003 Amadeus Software Limited

Tip 23 – V6 Work Library in V8

• Allocate libref of user with v6 engine to

the current work library.

• Use as normal work area

• Will be cleared out when session

finishes

Page 25: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 25 Copyright © 2003 Amadeus Software Limited

Tip 24 – Clear up Work Library

Jobs can fail due to work space running out.

When you no longer need a data set delete it.

Page 26: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 26 Copyright © 2003 Amadeus Software Limited

Tip 25 – Commenting out Large Sections of Code

Think about using a macro to comment out

code. Just place code in macro and don’t call the

macro.

Page 27: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 27 Copyright © 2003 Amadeus Software Limited

Tip 26 – Run Cancel

Checks the syntax without running

the data step.

Page 28: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 28 Copyright © 2003 Amadeus Software Limited

Tip 27 – Copy non SAS Files

Use proc download to copy files from a server to

your pc, they don’t have to be SAS files.

Page 29: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 29 Copyright © 2003 Amadeus Software Limited

Tip 28 – Rename your Variables

Rename your variables without the use of a

data step.

Page 30: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 30 Copyright © 2003 Amadeus Software Limited

Tip 29 – Formatting Titles With Sysfunc

Page 31: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 31 Copyright © 2003 Amadeus Software Limited

Tip 30 – Libname Engines

Use a engine to access new types of data.

Libname olddata v6 ‘C:\temp’;

Engine

Engine Type of Data

V6 Access old V6.08 to V6.12 SAS Data Sets

V604 Access old V6.03 or V6.04 SAS Data Sets

V8 Access V8 SAS Data Sets

XML Access XML Files

Oracle Access Oracle Tables

DB2 Access DB2 Tables

Teradata Access Teradata Tables

ODBC Access Data Though ODBC

and many more

Page 32: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 32 Copyright © 2003 Amadeus Software Limited

Tip 31 – Easy to spot unbalanced quotes in

Enhanced Editor

Just look at the colours

Page 33: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 33 Copyright © 2003 Amadeus Software Limited

Tip 32 – Describing Data Step Views

New in version 8 is the ability to find out the code

behind a data step view.

Page 34: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 34 Copyright © 2003 Amadeus Software Limited

Tip 33 – WSAVE Command

The WSAVE command saves your window setting

changes (e.g. colour, position, and size). After you

have changed to your desired settings issue the

WSAVE command from the command line.

To return to the default settings delete the catalog

entry SASUSER.PROFILE.window.WSAVE, as

this is where you changes have been saved.

Page 35: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 35 Copyright © 2003 Amadeus Software Limited

Tip 34 – Skip and Page for a Better Log

Use the SKIP and PAGE statements to separate steps or

particular parts of your program in the log. These

statements allow you to customise your log for ease of

reading.

Page 36: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 36 Copyright © 2003 Amadeus Software Limited

Tip 35 – Command Line Commands

You can still use some of the old line commands in the

enhanced editor. Just run them from the command line

with the prefix of :

Supported

Comments

are:

I,IA,IB,R,D

Page 37: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 37 Copyright © 2003 Amadeus Software Limited

Tip 36 – ODS To Excel

We Can take advantage of the way Excel

interoperates HTML to create our own Excel

spreadsheets

Page 38: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 38 Copyright © 2003 Amadeus Software Limited

Tip 37 – SASHELP Views

There are a number of views available in

SASHELP which contain information about your

SAS session. They can be very useful to use

during SAS processing.

Page 39: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 39 Copyright © 2003 Amadeus Software Limited

Tip 38 – File Print

Send your data step put statements to the output

window by using file print. Very useful with ODS.

Page 40: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 40 Copyright © 2003 Amadeus Software Limited

Tip 39 - Autosave

Did you just crash SAS, or did you forget to save your SAS

program. ‘No Worries Mate’ with SAS autosave.

Goto Tools-Options-Preferences under the edit tab is an

autosave option.

Page 41: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 41 Copyright © 2003 Amadeus Software Limited

Tip 40 – dm Statement

To run SAS commands from SAS code use the

‘dm’ statement

Page 42: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 42 Copyright © 2003 Amadeus Software Limited

Tip 41 – No More PGM with dm

A feature(?) of V8 is if you run a dm command from the

enhanced editor the program editor appears and becomes

the active window.

You can stop this by adding an editor statement before and

after the command.

Page 43: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 43 Copyright © 2003 Amadeus Software Limited

Tip 42 – Formats from Within Formats

Formats can be used within a format definition.

Page 44: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 44 Copyright © 2003 Amadeus Software Limited

Tip 43 – Multilabel Formats

Page 45: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 45 Copyright © 2003 Amadeus Software Limited

Tip 43 – Multilabel Formats

Page 46: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 46 Copyright © 2003 Amadeus Software Limited

Tip 44 – Pre-Load Formats

Page 47: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 47 Copyright © 2003 Amadeus Software Limited

Tip 44 - Pre-Load Formats

Page 48: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 48 Copyright © 2003 Amadeus Software Limited

Tip 45 – Misstext

Page 49: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 49 Copyright © 2003 Amadeus Software Limited

Tip 46 – Variable Values in Title

Page 50: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 50 Copyright © 2003 Amadeus Software Limited

Tip 47 – Proc Summary with Types

New to V8 we can now select what types are

required.

Page 51: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 51 Copyright © 2003 Amadeus Software Limited

Tip 48 – Proc Summary with Ways

Page 52: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 52 Copyright © 2003 Amadeus Software Limited

Tip 49 - Sleep

If you are not already asleep, use the sleep

function to send your SAS session to sleep for a

number of seconds. Very useful when running x

commands and they may not have finished.

Page 53: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 53 Copyright © 2003 Amadeus Software Limited

Tip 50 – Don’t Tell Everybody Everything You

Know

?

Page 54: 50 Base SAS Tips - Lex Jansen · Title: Automated Scorecard Application Author: Steve Hanks Created Date: 1/15/2014 8:27:37 AM

Slide 54 Copyright © 2003 Amadeus Software Limited

Sources of Information

• Amadeus Software Ltd Technical Staff

• Phil Holland of Holland Numerics

• Phil Mason of Wood Street Consultants

• Alan Davies of Scorpio Software Services

• SAS Online Doc

• SAS Today a Year of Terrific Tips