90
Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 1 We Have Computers, We Should Use Them! Presented by: Steve First 2997 Yarmouth Greenway Drive, Madison, WI 53711 Phone: (608) 278-9964 • Web: www.sys-seminar.com Old Process New Process Input Data Old result file New result file Equal?

We Have Computers, We Should Use Them!

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 1

We Have Computers, We Should Use Them!

Presented by: Steve First2997 Yarmouth Greenway Drive, Madison, WI 53711Phone: (608) 278-9964 • Web: www.sys-seminar.com

Old Process New Process

Input Data

Old result file New result fileEqual?

Page 2: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 2

This paper was written by Systems Seminar Consultants, Inc.SSC specializes in SAS software and offers:

• Training Services• Consulting Services• Help Desk Plans• Newsletter Subscriptions to The Missing Semicolon™

COPYRIGHT© 2016 Systems Seminar Consultants, Inc.

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 prior written permission of SSC. SAS is a registered trademark of SAS Institute Inc. in the USA and other countries. The Missing Semicolon is a trademark of Systems Seminar Consultants, Inc.

WISAS: How Did We Get Here?

Page 3: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 3

WISAS?

Page 4: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 4

Introduction

Background:

• Me• SAS• SSC• WISAS

Page 5: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 5

Why is Wisconsin Famous?

• Cheese• Beer• Bratwurst• Cold Weather (How cold?)• Snow plow hockey• No high speed trains• Illinois tourists• University of Wisconsin • Madison • A hotbed of SAS users• Not nearly as cold as Minnesota• Not nearly as boring as Iowa

Page 6: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 6

Who Am I?

• Computer science major • SAS user since 1976• Done lots of things (none of them very well)• From Wisconsin• Teller of Side Splitting Jokes • Certainly do not know everything.

Page 7: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 7

Who Am I?

• Graduated University in 1974• Cobol programmer F. W. Woolworth 1975 • Cobol programmer UW Madison Until 1977

Heard about SAS • Cobol, systems programmer John Deere Dubuque Works Until 1980

Started using SAS, told everyone, attended class.• Wisconsin DOT Systems, SAS sup (full time to 1983, part time to1987)• Started SSC 1983

Page 8: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 8

My Influences

• Started as a Math major• Moved to Computer Science (open book tests! )

• First Comp Sci Professor Lonny Winrich• Donald Knuth• An unknown Ccbol consultant• Lemuel Jones• Allen Hershey• Joe Guepfer• Gary Larson• My brothers-in-law• LeRoy Bessler• Many others

Page 9: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 9

My Influences

First Comp Sci Professor Lonny Winrich

• Instilled a love of programming• Had been an applications programmer at Honeywell• Taught practical techniques and applications

(Use a displaying statement to debug logic. ie. PUTLOG)

Page 10: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 10

Who Said This And When?

“The process of preparing programs for a digital computer is especially attractive because it not only can be economically and scientifically rewarding, it can also be an aesthetic experience much like composing poetry or music.”

Page 11: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 11

Who Said This And When?

“The process of preparing programs for a digital computer is especially attractive because it not only can be economically and scientifically rewarding, it can also be an aesthetic experience much like composing poetry or music.”

Donald Knuth - The Art of Computer Programming Volume 1: Fundamental Algorithms (1969)

Page 12: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 12

My Influences

Donald Knuth

• Professor Emeritus Stanford• True pioneer in computer science and mathematics• Art of Computer Programming• Tek• Latek• Met him in Madison• License plate 32768

Page 13: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 13

My Influences

Lemuel Jones

• Corporate Development Trainer IBM• Small but very dynamic individual• Gave a week long workshop in 1976• Instilled teamwork• Instilled the idea for looking for the unusual and opposites

• Elevators• Colas• Freeways• Develop teamwork

Page 14: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 14

My Influences

Unknown Cobol Code Consultant

• Saw a program that was structured at Woolworth that was beautiful.

Page 15: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 15

My Influences

Allen Hershey

• Mathematician at Naval Weapons Lab• Developed Hershey Fonts

• What are the Hershey Fonts?• Some similarities to Knuth

Page 16: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 16

My Influences

Joe Guepfer

• Humble machinist• One of the most brilliant people I have met• “Just look around, great ideas are all over the place.”

Page 17: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 17

My Influences

My brothers-in-law

A lawyer

• “Haven’t you written every program ever needed”?

An Engineer

• “Programming is something engineers do in their spare time”.• “What more than a spreadsheet is possibly needed”?

A Cheesemaker

• No comments on programming

Page 18: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 18

LeRoy Bessler

SAS Installer at Miller Brewing Company

• Installing SAS/GRAPH and graphics devices and printers• Thorough, ran every single graph in SAS/GRAPH manual • Protocol converters • Has been a good friend for a long time.• A steady supporter of sas and user groups all these years.

Page 19: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 19

SAS History

SAS Authors

• Jim Goodnight• John Sall• Tony Barr• Jane Hellwig

Page 20: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 20

SAS History 1966

• In 1966, there was no SAS. • Was need for a computerized statistics program to analyze vast

amounts of agricultural data frtom (USDA) grants.• Development critically important to members of the University

Statisticians Southern Experiment Stations, a consortium of eight land-grant universities that received the majority of their research funding from the USDA.

• The schools came together under a grant from (NIH) to develop a general-purpose statistical software package to analyze all the agricultural data they were generating.

• The resulting program, the Statistical Analysis System, gave SAS both the basis for its name and its corporate beginnings.

Page 21: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 21

Academic Roots and Early Leadership

• North Carolina State University in Raleigh became leader in consortium.(It had a more powerful mainframe computer).

• The project eventually found a home in the Statistics Department.• NCSU faculty members Jim Goodnight and Anthony Barr emerged as

the project leaders.• Barr creating the architecture • Goodnight implemented the features that sat on top of the architecture

and expanded the system's capabilities.

Page 22: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 22

1972

• NIH discontinued funding• consortium paid $5,000 apiece each year to allow NCSU to continue

developing and maintaining the system and supporting their statistical analysis needs.

Page 23: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 23

Expanding Team and Clientele

• Over the years SAS software was licensed by pharmaceutical companies, insurance companies and banks, as well as by the academic community that had given birth to the project.

• Jane Helwig, another Statistics Department employee at NCSU, joined the project as documentation writer,

• John Sall, a graduate student and programmer, rounded out the core team.

Page 24: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 24

First Users Conference

• More than 300 people attended the conference in 1976. • Growing customer base that already numbered close to 100

academic, government and corporate entities, • Evident that success as an independent operation was possible.

Page 25: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 25

Incorporation

• Goodnight, Barr, Helwig and Sall left NCSU and formed SAS Institute Inc. – a private company "devoted to the maintenance and further development of SAS."

• They opened offices in a building at 2806 Hillsborough Street, across from the university.

Page 26: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 26

1976- 1980 Laying the Foundation

• In 1976 computers filled rooms the size of small houses, and programs and data were stored on punch cards.

• Base SAS, consisting of about 300,000 lines of code, would produce about 150 boxes of cards - a stack more than 40 feet high.

• Laid end to end, the boxes of cards would stretch more than 180 feet.

Page 27: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 27

1980s

• Expanding frontiers: technology, work environment and geography• The growth of SAS in the next decade was phenomenal: Inc. magazine

named SAS one of the fastest-growing companies in America for five consecutive years.

• The new headquarters campus - huge compared to the Hillsborough Street location - grew from one building with offices for 50 employees to 18 buildings, including a training center, publications warehouse and video studio.

• SAS also expanded its geographic boundaries, opening new offices on four continents and its first US regional sales offices. By the end of the decade, SAS had nearly 1,500 employees worldwide.

Page 28: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 28

1990s Mining the Opportunities

• SAS would grow its work force to more than 7,000 people around the world, with employees on every continent, in every major US city and in the capitals of international commerce all over the planet.

Page 29: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 29

Into the 21st Century

• SAS celebrated its 25th anniversary in 2001, right on the heels of the turn of the millennium and the Y2K frenzy that seemed to engulf the world of technology.

• With a new logo and tagline - THE POWER TO KNOW® - in place, SAS set off to increase its visibility and global recognition.

Page 30: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 30

2016

• Number of Countries Installed 148 • Total Worldwide Customer Sites 80,000 sites.• Fortune Global 500® Customers 91 of the top 100 Worldwide

Employees 14,059 total employees

Page 31: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 31

History of SSC

• Part time training starting in 1983• SAS training was a big part of business• From the start, also did project work to keep us busy and honest • Full time by 1987.• First employee 1988• Employee count has varied from 1 to 25 over the years.• Lots of systems, conversions, training.

Page 32: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 32

SSC Standards

• Customer service comes first, we are the best free workers there are.• Everybody codes and trains• Part time training starting in 1983• SAS training was a big part of business• From the start, also did project work to keep us busy and honest • Full time by 1987• First employee 1988• Employee count has varied from 1 to 25 over the years• Use computers to automate projects whenever possible• Code is documented!!!.

Page 33: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 33

SSC Standards

“The program isn’t finished until a person of normal intelligence can understand it”.

Simple things:

• Good naming conventions• Good directory standards• Comments and documentation

Page 34: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 34

Comment and Code Clearly

Comments and clear code are important in any language.

Commenting tips:• Use comments.• Write a header box and change the log.• Code flower boxes before separate routines.• Comment as you develop the code, not after.• Add comments to each line, if necessary.• Be sure to comment difficult code.• Code blank lines between each programming step.

Page 35: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 35

A Commenting Example

An Adequate Program

data sjfsas.partdesc;infile tapein;input partno $1-9 desc $38-67 ;

proc sort data=sjfsas.partdesc; by partno;proc contents data=sjfsas.partdesc;title 'Sjfsas.Partdesc';run;

Page 36: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 36

A Commenting Example

A Better Program

/********************************************************************//* SAS Warranty System program wtypgm10 *//* *//* description: *//* this creates a sas dataset sjfsas.partdesc from an input tape.*//* this dataset will be merged with other warranty data later. *//* *//* input: tape from sjf systems. *//* output: sas dataset sjfsas.partdesc *//* schedule: annually *//* date written: 27 january 2016 *//* author: Steven First madison wi (608) 278-9964 *//* revisions: *//********************************************************************/

Page 37: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 37

A Commenting Example (continued)

data sjfsas.partdesc; /* build sas ds */infile tapein; /* raw input filedef */input partno $1-9 /* part number */

desc $38-67 /* description */; /* end of input */

run; /* end of step */proc sort data=sjfsas.partdesc; /* run proc sort in */by partno; /* part number order */run; /* end of step */

proc contents data=sjfsas.partdesc; /* run proc contents */title 'Sjfsas.Partdesc'; /* title */run; /* end of step */

/****************** end of program wtypgm10 *********************/

Page 38: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 38

WISAS History

• Mid 1980’s• I got a list of SAS users • Enlisted help from Joy First, Nelson Eismann, Carey Fleischmann

Bill Hurley, Bill Kuth, Dave Pinger, LeRoy, many others• First meeting was at American Family in Madison• Got a newsletter, lots of great volunteers• Lots of good speakers• Bounced around Madison, Milwaukee, Chicago• Costs were informal, out of pocket • Regional groups starting about the same time.

Page 39: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 39

WISAS History

• Rented Space at technical college in Grayslake, IL.• After a couple of years, LeRoy took over.• And here we are!!!!!

Page 40: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 40

Why Do I (We) Like SAS?

A language of defaults.

• Libraries (work)• Members (data ; proc print;)• Columns• Integrated dictionary• Data step.

• Automatic loop• Automatic open / close of files• Automatic initialization• Automatic eof check• Automatic output

• Procs• Many assumed actions and statistics

Page 41: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 41

Why Do I (We) Like SAS?

• A simple rectangular shaped file structure.• A good programming language

• Read and write any file• First. , last. control breaking with BY processing• Built in data dictionary • IF, WHERE, do loops, arrays• Link, return • Function library• Formats, informats• Can read files dynamically (all files in a directory).• Macro language• Interface is much improved with enterprise guide.

Page 42: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 42

My First SAS JobI spent 10 years in Iowa (in a 3 year period)

A data center transfers thousands of mostly blank records down acommunications line. It takes a long time to move the data.

80 byte recordsxxxxxxxxx

80 byte recordsxxxxxxxxx

Data Center 1- - - - - - - - - - -

Data Center 2

RJE

Page 43: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 43

A Cobol SolutionWrite two programs to "pack" and "unpack" data. (8 hours)

80 byte recordsxxxxxx

Data Center 1- - - - - - - - - - -

Data Center 2

PGM1 80 byte recordsxxx xxx xxx xxx

80 byte recordsxxx xxx xxx xxx

80 byte recordsxxxxxx

RJE

PGM2

Page 44: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 44

A SAS Solution – Two Small Programs(JCL defined both files with LRECL=80).

DATA _NULL_; /* DON'T NEED DS */INFILE IN; /* RAWFILE IN */FILE OUT; /* RAWFILE OUT */INPUT @1 TWENTY $CHAR20.; /* READ 20 CHAR */PUT TWENTY $CHAR20. @; /* 20 OUT, HOLD PTR */

RUN; /* END OF STEP */

The Reversing ProgramBe careful with @@.DATA _NULL_; /* DON'T NEED DATASET*/ INFILE IN; /* RAW FILE IN */ FILE OUT LRECL=80; /* FILEOUT */ INPUT /* READ TWENTY/LOOP */

TWENTY $CHAR20. /* FIXED PTRS CAUSE */ @@ ; /* LOOPS, BE CAREFUL */

IF TWENTY NE ' ' THEN /* IF NONBLANK ? */PUT /* OUTPUT 20 */

@1 TWENTY $CHAR20.; /* $CHAR SAVES BLANKS*/ IF _N_ > 20 THEN /* A GOOD IDEA WHILE */

STOP; /* TESTING */ RUN; /* END OF STEP */

Page 45: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 45

A Subsetting ProgramSelect part of a file.

DATA _NULL_; /* DON'T NEED DATASET */ INFILE IN; /* RAW FILE IN */FILE OUT; /* RAW FILE OUT */INPUT @5 ID $CHAR1.; /* INPUT FIELDS NEEDED */IF ID='2'; /* WANT THIS RECORD? */PUT _INFILE_; /* YEP, WRITE IT OUT */

RUN;

Selecting a Random SubsetRandomly select about 10% of a file.

DATA _NULL_; /* NO DATASET NEEDED */INFILE IN; /* RAW FILE IN */FILE OUT; /* RAW FILE OUT */INPUT; /* READ A RECORD */IF RANUNI(0) LE .10; /* TRUE FOR APP. 10% */ PUT _INFILE_; /* WRITE OUT OBS */

RUN; /* END OF STEP */

Page 46: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 46

A Cobol Generated ReportA sparse matrix crossing two variables

A PROC FREQ Alternative

PROC FREQ; TABLE TERMID * OPERATOR / LIST;

RUN;

Number of Transactions by Termid and Operator

Operator TERMID 0001 0002 0003 0004 . . . 0200

0001 55 0002 24 12 0003 2

.

. 0150 1

Page 47: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 47

A Mass Change ProgramChange all SYSOUT=A to SYSOUT=* in a PROC Library

Issues:

• many directories or PDS members• production is affected• change logic may be complex• back up before, be careful• LRECL=80, use PROC SOURCE• sample lib PDSFIND, PDSCHANG

Page 48: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 48

A Mass Change Program (continued)Mass Change Flow

SOME PDSA B

ANOTHER PDSA B

./ ADD NAME = A. . . . . .

./ ADD NAME = B

./ ADD NAME = A. . . . . .

./ ADD NAME = B

PROCSOURCE

DATA STEPSCAN REPL

IEBUPDTE

Page 49: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 49

The Mass Change SAS Code// EXEC SAS //PDSIN DD DSN=SOMEPDS,DISP=SHR//SEQIN DD UNIT=DISK,SPACE=(TRK,500)//SEQOUT DD DSN=&&SEQOUT,DISP=(,PASS),// UNIT=DISK,SPACE=(TRK,500)

PROC SOURCE INDD=PDSIN OUTDD=SEQINSELECT . . .; / MODIFY AS NEEDED /

RUN;

DATA _NULL_; INFILE SEQIN; INPUT @1 WHOLE $CHAR80.;COL=INDEX(WHOLE,'SYSOUT=A');IF COL NE 0 THEN

SUBSTR(WHOLE,COL,8)='SYSOUT=*'; FILE SEQOUT;PUT @1 WHOLE $CHAR80.;

Page 50: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 50

The Mass Change SAS Code (continued)RUN;

// EXEC PGM=IEBUPDTE//SYSPRINT DD SYSOUT=*//SYSUT2 DD DSN=SOMEOTHR.PDS,DISP=OLD//SYSIN DD DSN=&&SEQOUT,DISP=(OLD,DELETE)

Notes:• Backup before starting, be careful!!

Page 51: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 51

Programs that Write Other Programs1. Use SAS to read data, figure logic.2. Build another program.3. Submit 2nd program to Internal reader or file.

Applications:

• job schedulers• disk management programs• many others

Be careful if deleting data!

Page 52: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 52

Programs that Write Other ProgramsThere goes the JES Queue.

A system to automate job submission

JOB LIBRARY//JOB1//JOB2//SCHDJOB

Internalreader

SCHDJOB

Page 53: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 53

My Favorite SAS Feature• “@” at end of the INPUT statement prevents the next INPUT statement

from reading a new record.• Trailing @ “holds” the current record.

Syntax: INPUT . . @;

• The current record remains in the buffer when the next INPUT statement is executed.

• The column pointer stays in its current location.• The @ input hold is released:

- at the end of the current DATA step iteration (loop)- when an INPUT without trailing @ executes, including: INPUT;- INPUT reads past the end of the current record (flowover)

Note: If a trailing @ hold is in effect the statement INPUT; releases the hold only. It does not read a new record or place data in the PDV.

Page 54: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 54

A Trailing @ Example

Read a file with three record types.

• An account file has at least three kinds of records each with a unique layout:

type 05 - person recordtype 15 - address recordtype 21 - sales record

• The records can appear in any order and are not necessarily related.

The problem:• Build a separate SAS dataset for each of the three types listed above.• Delete any other records found.

Page 55: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 55

Three Record Type Example Solution

Use @ to read TYPE then conditionally read other lines.

data person (keep=fname lname)address (keep=street city state zip)sales (keep=sales expense);

infile rawin;input @1 type $2. @; /* input and hold */

(continued)

05 BETH SMITH15 12 NORTH AVE MADISON WI 53713 21 233.11 94.1221 4009.21 322.1205 CHRIS JONES15 675 FIRST ST MADISON WI 5371121 6153.32 1507.12

fileRAWIN

Page 56: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 56

Three Record Type Example Solution (continued)

if type='05' then do; /* is it a 05 ? */input @4 fname $8.

@12 lname $10.;output person; /* write to PERSON */

end;else if type='15' then do; /* is it a 15 ? */

input @4 street $12.@17 city $7.@25 state $2. @28 zip $5.;

output address; /* write to ADDRESS */end;else if type='21' then do; /* is it a 21 ? */

input @4 sales 7.2 @12 expense 7.2 ;

output sales; /* write to SALES */end;run;

Page 57: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 57

The Absolute Best Data Step Debugging StatementPUTLOG !!!!!!

Syntax:

PUTLOG ‘constants’ variable format variable= _all_;

Notes:• PUTLOG displays PDV data as it goes by.

Page 58: We Have Computers, We Should Use Them!

58

Debugging Data Steps

Why wasn’t Bloomington selected?

27 data mycity;28 infile datalines;29 Input @1 state $2. @10 County $10.30 @20 City $10. @35 Rate;31 If State ='MN';32 If County='Hennepin';33 if City = 'Bloomington';34 datalines;MN Hennepin Bloomington 100WI Dane Monona 200

NOTE: The data set WORK.MYCITY has 0 observations and 4 variables.

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 58

Page 59: We Have Computers, We Should Use Them!

59

The Best Debugging Statement

PUTLOG Displays Data step values at stategic spots.

42 data mycity;43 infile datalines;44 Input @1 state $2. @10 County $10.45 @20 City $10. @35 Rate;46 putlog '*** Before State Check' _all_;47 if State ='MN';48 putlog '*** Before County Check' state= county= city=;49 if County='Hennepin';50 putlog '*** Before City Check' state= county= city=;51 if City = 'Bloomington';52 putlog '*** After City Check' state= county= city=;53 datalines;

*** Before State Checkstate=MN County=Hennepin City=Bloomingt Rate=100 _ERROR_=0 _N_=1*** Before County Checkstate=MN County=Hennepin City=Bloomingt*** Before City Checkstate=MN County=Hennepin City=Bloomingt*** Before State Checkstate=WI County=Dane City=Monona Rate=200 _ERROR_=0 _N_=2*** Before State Checkstate=IL County=Cook City=Chicago Rate=300 _ERROR_=0 _N_=3Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 59

Page 60: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 60

Pseudo-Variables

Pseudo-variables are special data step variables to help your data step programming.

Syntax:

IN =variable tells which dataset contributed to current observationEND =variable tells when observation is the last one FIRST.by-variable tells if observation is first in a BY group LAST.by-variable tells if observation is last in a BY group

Notes:• These variables have values of 1 (true) or 0 (false). • They are present in a PDV but not in the output dataset. • FIRST. and LAST. variables are automatically created by the BY statement. • You must create END and IN variables.

Page 61: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 61

An Example Showing Pseudo-Variables

Merge Person and Sales datasets.

Person Dataset Salesds Dataset

OBS Name Division OBS Name Sales

1 ANDREW S 1 ANDREW 3232.652 BENJAMIN S 2 ANDREW 4322.323 BETH H 3 BARBARA 1645.12

4 BETH 3156.76

data persales; merge person(in=Onp)

salesds(in=Ons) end=Eof; by name;

run;

Page 62: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 62

An Example Showing Pseudo-Variables (continued)

----Dataset Persales------ ------Pseudo Variables------First. Last.

OBS Name Division Sales Onp Ons Eof Name Name 1 ANDREW S 3232.65 1 1 0 1 0 2 ANDREW S 4322.32 1 1 0 0 1 3 BARBARA 1645.12 0 1 0 1 1 4 BENJAMIN S . 1 0 0 1 1 5 BETH H 3156.76 1 1 1 1 1

Program data vector

Page 63: We Have Computers, We Should Use Them!

Other Favorite SAS Features

• PROC FREQ to get distributions (count things).• PROC SUMMARY/MEANS to get quick totals for tie out,

multi level summaries, classification, analysis • PROC FORMAT for formatting, function use, informatting.

Many others.

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 64

Page 64: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 64

A Classic Macro Problem

• Each day you read a SAS dataset containing data from counties in Wisconsin.

• Anywhere between 1 and 72 counties might report that day.

PERM.COUNTYDT

Obs COUNTYNM READING

1 ASHLAND 1252 ASHLAND 6113 BAYFIELD 1014 BAYFIELD 1015 BAYFIELD 2226 WASHINGTON 143

Page 65: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 65

One Solution

Solution: Write a SAS Macro. A multi-step macro can communicate between steps.

%MACRO COUNTYMC; /* MACRO START */ DATA _NULL_;SET PERM.COUNTYDT END=EOF; /* READ SAS DATASET */BY COUNTYNM; /* SORT SEQ */ IF FIRST.COUNTYNM THEN DO; /* NEW COUNTY ? */

NUMCTY+1; /* ADD 1 TO NUMCTY */CTYOBS=0; /* OBS PER COUNTY TO 0 */END;

CTYOBS+1; /* ADD 1 OBSER FOR CTY */IF LAST.COUNTYNM THEN DO; /* EOF CTY,MAKE MAC VARS*/

CALL SYMPUT('MCTY'!!LEFT(PUT(NUMCTY,3.)),COUNTYNM);CALL SYMPUT('MOBS'!!LEFT(PUT(NUMCTY,3.)),LEFT(CTYOBS));END;

IF EOF THEN /* VERY LAST OBS ? */CALL SYMPUT('MTOTCT',NUMCTY); /* MAC VAR NO DIF CTYS */

RUN;

Page 66: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 66

The Solution (continued)

%PUT *** MTOTCT=&MTOTCT; /* DISPLAY NO OF CTYS */

%DO I=1 %TO &MTOTCT; /* LOOP THRU ALL CTYS */%PUT *** LOOP &I OF &MTOTCT; /* DISPLAY PROGRESS */PROC PRINT DATA=PERM.COUNTYDT; /* PROC PRINT */WHERE COUNTYNM="&&MCTY&I"; /* GENERATED WHERE */OPTIONS PAGENO=1; /* RESET PAGENO */TITLE "REPORT FOR COUNTY &&MCTY&I";

/* TITLES & FOOTNOTES */FOOTNOTE "TOTAL OBSERVATION COUNT WAS &&MOBS&I";

RUN;%END; /* END OF %DO */%MEND COUNTYMC; /* END OF MACRO */%COUNTYMC /* INVOKE MACRO */

Page 67: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 67

A Call Execute Example

CALL EXECUTE can also dynamically generate and submit code.

data pass2;set perm.countydt;by countynm;if first.countynm then ctyobs=0;ctyobs+1;if last.countynm then

call execute('PROC PRINT DATA=PERM.COUNTYDT; ' !!'WHERE COUNTYNM="' !!countynm !!

'";' !!'OPTIONS PAGENO=1;' !! 'TITLE "REPORT FOR COUNTY ' !!countynm !!

Page 68: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 68

A Call Execute Example (continued)

The rest of the program follows.

'";' !! 'FOOTNOTE "TOTAL OBSERVATION COUNT WAS ' !!put(ctyobs,2.) !!'";' !!'RUN;' );

run;

Page 69: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 69

A Call Execute Example (continued)

The resulting SAS Log:

NOTE: CALL EXECUTE generated line.1 + PROC PRINT DATA=PERM.COUNTYDT;

WHERE COUNTYNM="ASHLAND";OPTIONS PAGENO=1;TITLE "REPORT FOR COUNTY ASHLAND";FOOTNOTE "TOTAL OBSERVATION COUNT WAS 2";RUN;

NOTE: CALL EXECUTE generated line.2 + PROC PRINT DATA=PERM.COUNTYDT;

WHERE COUNTYNM="BAYFIELD";OPTIONS PAGENO=1;TITLE "REPORT FOR COUNTY BAYFIELD";FOOTNOTE "TOTAL OBSERVATION COUNT WAS 3";RUN;. . .

Page 70: We Have Computers, We Should Use Them!

Exploring Data Through The EG Query Builder

• A query is a task that allows you to manipulate data tables, and subset data.

• The Query Builder in Enterprise Guide generates PROC SQL code behind the scenes.

• Join tables• Select variables• Filter data• Sort data• Change data source• Compute columns

• Set up prompts• De-dup observations• Change query options• Add titles, footnotes• Limit output• And more

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 71

Page 71: We Have Computers, We Should Use Them!

Exploring Data Through The Query Builder

• The Query Builder uses point and click to create PROC SQL queries.

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 72

Page 72: We Have Computers, We Should Use Them!

SQL in the Query Builder

• Generates PROC SQL code behind the scenes including pass through.

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 73

Page 73: We Have Computers, We Should Use Them!

Joining Tables with the Query Builder

• Up to 32 tables can be joined in a query.

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 74

Page 74: We Have Computers, We Should Use Them!

Summary Tables Task (PROC TABULATE)

• Uses analysis and classification variables to roll up data.

• Calculates selected statistics and classifications

• Can be customized in a Report Preview Area

• User can see the rows and columns, variable roles, etc. before the report is produced.

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 75

Page 75: We Have Computers, We Should Use Them!

Summary Tables Task

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 76

Page 76: We Have Computers, We Should Use Them!

Summary Tables Task

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 77

Page 77: We Have Computers, We Should Use Them!

Summary Tables Task - Output

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 78

Page 78: We Have Computers, We Should Use Them!

A Partial SAS Log

31 libname winfile '/ssctest/dir';NOTE: Libref winfile was successfully assigned as follows:

Engine: V9 Physical Name: /ssctest/dir

172 + data winfile.cust_info ;173 + %let _EFIERR_ = 0; /* set the ERROR detection */174 + infile '/ssctest/dir/cust_info.csv' delimiter = ',' 175 MISSOVER DSD lrecl=32767 firstobs=2 ;194 + input195 + cust_id_ $196 + Account_Number 197 + Account_Name $206 + ;207 + if _ERROR_ then call symputx('_EFIERR_',1); 208 + run;

NOTE: The infile '/ssctest/dir/cust_info.csv' is:Filename=/ssctest/dir/cust_info.csv,Owner Name=bsweinb,Group Name=sasdev,Access Permission=rw-r--r--,Last Modified=Mon Oct 19 09:13:37 2015,File Size (bytes)=118098274

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 79

Page 79: We Have Computers, We Should Use Them!

A Hand Drawn Flowchart

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 80

Page 80: We Have Computers, We Should Use Them!

The Datafile Table

80Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081

Page 81: We Have Computers, We Should Use Them!

Final Flowchart

8181Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 81

Page 82: We Have Computers, We Should Use Them!

Code Improvements

“Last Reference” of a file is recorded.•Could generate delete code•Perhaps generate, but require user to insert.

Long running steps.•Relatively easy to identify long running steps•What about macro that generate individually small steps, that together are repeated thousands of times and overall represent a significant elapsed time?

There are virtually unlimited opportunities for programs to examine run time statistics and make or at least suggest improvements automatically.

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 82

Page 83: We Have Computers, We Should Use Them!

Summarizing the Steps Dataset

13 Minutes21% of entir

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 83

Page 84: We Have Computers, We Should Use Them!

Bar Chart of Elapsed Time

FREQ. Percentage of Total Elapsed Time

1 3.09

1 2.20

1 2.08

1 2.63

1 2.31

1 7.67

1 21.47

1 2.60

1 3.77

3844 52.17

sas_step_no

Remaining

3540

3532

3526

3525

3524

3503

3440

546

544

Percentage of Total Elapsed Time

0 10 20 30 40 50 60

A Graph showing the Same Information

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 84

Page 85: We Have Computers, We Should Use Them!

Data Lineage

8585

CUST_IDS CUST_IDS_ADJ CUST_IDS_FINAL

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 85

Page 86: We Have Computers, We Should Use Them!

Data Lineage

8686

CUST_IDS CUST_IDS_ADJ CUST_IDS_FINAL

ID $10ADDR $10STATE $20

ID $10STATE $20ADDR $10

ID $10STATE $20ADDR $10

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 86

Page 87: We Have Computers, We Should Use Them!

Data Lineage

8787

CUST_IDS CUST_IDS_ADJ CUST_IDS_FINAL

ID $10ADDR $10STATE $20

ID $10STATE $20ADDR $10

ID $10STATE $20ADDR $10

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 87

Page 88: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 88

My Aunt Rose From Milwaukee

Page 89: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 89

Conclusions• The SAS system is still a very vibrant and flexible system• Applications are not always where you would expect them• I would encourage you to look for those “contrarian” applications• Keep a good sense of humor.

Page 90: We Have Computers, We Should Use Them!

Systems Seminar Consultants, Inc. | www.sys-seminar.com | 1-800-997-7081 90

Contact Us

SAS® Training, Consulting, & Help Desk Services2997 Yarmouth Greenway Drive • Madison, WI 53711(608) 278-9964 • Fax (608) 278-0065 www.sys-seminar.com

Steve First, President608-278-9964 x [email protected]