24
Copyright © SAS Institute Inc. All rights reserved. Efficient SAS Programming 2. February 2017 This webinar will be recorded. Please keep your computers on mute. Please engage, use the Questions function during the presentation! Georg Morsing Senior Manager Gert Nissen Technical Client Manager

Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

  • Upload
    ngohanh

  • View
    239

  • Download
    10

Embed Size (px)

Citation preview

Page 1: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Efficient SAS Programming2. February 2017

This webinar will be recorded.

Please keep your computers on mute.

Please engage, use the Questions function during the presentation!

Georg Morsing

Senior Manager

Gert Nissen

Technical Client Manager

Page 2: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Efficient SAS ProgrammingCoding Standard

• Highlight 22 recommendations on how to write your SAS program efficiently

• For SAS programmers with limited experience (0-5 years), but all SAS programmers can benefit from the content

• Example code for all 22 recommendations and we will demo a selection of them

• Previously documented as “Det gode SAS-program” in Danish

Page 3: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Efficient SAS Programming

Coding Standard

• Consistency

• Easy to read

• Easy to maintain

• Re-use

• Performance

22 Recommendations

Example: SAS coding standard from an organization in Denmark

Page 4: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

SAS Programming – 22 Recommendations Coding Standard

General

1. Standard Header

2. Standard Indent

3. Divide steps & Comments

4. Use %INCLUDE

5. Modern Program Editor

Order – Your Code

10. SAS Program

11. Compile Time Statements in DATA step

12. In DATA Step

13. In PROC Steps

14. Finish one table at a time

15. Columns in your Table

Reduce Response Time16. Reduce Columns

17. Reduce Rows

18. Use Index

19. Use Views

20. Reduce Steps

21. Store numbers as characters

22. Use ELSE statement

Reduce Response Time – Course:SAS Programming 3: Advanced Techniques and Efficiencies

Names

6. Standard

7. Tabels

8. Columns

9. Formats

Page 5: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#01 Standard HeaderTip: Create Abbreviation Macro

Create

Use

Page 6: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#05 Modern SAS Program Editor

Page 7: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Januar 2013

• SAS® Enterprise Guide® 6.1

Oktober 2014

• SAS® Enterprise Guide® 7.1

August 2015

• SAS® Enterprise Guide® 7.11

Februar 2016

• SAS® Enterprise Guide® 7.12

November 2016

• SAS® Enterprise Guide® 7.13

#05 SAS Programming in SAS Enterprise GuideMany improvements specific for the SAS programmer

Page 8: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

• Autocomplete, show SAS-syntax

• SAS procedures, statements, options

• SAS library, tables, columns

• SAS formats, functions

• Macro variables, macro statements

• Syntax tool tips, mouse over help

• SAS procedures, statements, options, functions, formats

• Format code, code-beautifier

• Indent, format code

• Analyze program, flow diagram

• Improved SAS Log

• 3 types: Log, Project Log, Log Summary

• Better handling of incomplete code

• Style Manager

• Show, select and edit ODS styles

• Send To (MS Office Add-in)

• Explorer

• Metadata

• Server connections

• Security

• Prompt Manager

• SAS Stored Processes

• Fully integrated in the SAS platform

Many improvements specific for the SAS programmer

Version 4.3, 5.1 and 6.1

http://support.sas.com/documentation/onlinedoc/guide

#05 SAS Programming in SAS Enterprise Guide

Page 9: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

• SAS System Options Viewer

• SAS Macro Variable Viewer

• Program “History”

• Track changes

• Compare and commit changes to a program

• Smart highlighting of code

• Upload data to SAS LASR Analytics Server

Many improvements specific for the SAS programmer

Version 7.1

http://support.sas.com/documentation/onlinedoc/guide

• Filter your data - type a WHERE expression

• Enable SAS Enterprise Guide to automatically check for software updates

• Zoom feature – program, log, data, HTML results, process flow

• New Data Step Debugger tool

• Upload data to SAS Cloud Analytics Services (CAS)

Version 7.11, 7.12, 7.13

#05 SAS Programming in SAS Enterprise Guide

Page 10: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#06 NamingCreate a standard

• Capital letter ?• Underscores ? • Number of words in a name ?• Is it OK to shorten words ? • Use numbers as part of the

name?• Only English letters ?

Naming standard

Page 11: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#07 TablesNaming Standard

1. A name that describe the data

2. Do not re-use table names

3. Better to truncate name than shorten the name

4. Use multiple words separated by underscores (max 3)

5. Use views if you need copies of the same data (see #19)

Page 12: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#08 ColumnsNaming Standard

1. Describe the content, hire_date instead of hired

2. Use underscores between words and max 3 words

3. Consistent numbering, Month_01 instead of Month_1

4. Use truncate of name if when needed, truncate Salary to SAL instead of SLRY

5. Temporary names should start with t_ (easy to drop them)

6. Use _dummy, _date, _time etc

7. Use first letter from table name when using IN option

8. Use a consistent name like last_obs when using END option

Page 13: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#08 FormatsNaming Standard

1. End formats with _fmt when possible, like age_fmt

2. Use underscores in the name if needed

3. Truncate the name if needed

4. Name the format catalog: Formats

Page 14: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#10 SAS programRecommended Order

1. OPTIONS

2. FILENAME & LIBNAME

3. Macro variables

4. ODS statements

5. TITLE & FOOTNOTE

6. Other general statements

7. Formats, macros, functions

8. TITLE, FOOTNOTE & ODS

9. DATA/PROC steps:

• Reading data

• Manipulating data

• Analysis and output

10. Closing

• Reset values to default

• Delete titles & footnotes

• Delete tables, formats, macros, etc.

Page 15: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#11 Compile Time Statements in the DATA Step

• Can be placedanywhere

• DROP

• KEEP

• RENAME

• LABEL

• RETAIN

12 Compile Time Statements

Recommended order

• LENGTH, ATTRIB, RETAIN

• BY, WHERE, INFORMAT, ARRAY

• DROP, KEEP, LABEL, FORMAT

• RENAME

Page 16: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

#12 The order inside your DATA Step

DATA

LENGTH

SET, MERGE, BY, WHERE

Validate data

Change data

New columns

KEEP, RENAME

LABEL, FORMAT

OUTPUT

Create new tables

Create new columns

Reading data

Validating data

Fix problems in your data

Create new columns

Specify columns to be saved in the new table(s)

Create labels and formats

Store the row in the table(s)

Page 17: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

SAS Coding Standard

Page 18: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

SAS Programming – 22 Recommendations Coding Standard

General

1. Standard Header

2. Standard Indent

3. Divide steps & Comments

4. Use %INCLUDE

5. Modern Program Editor

Order – Your Code

10. SAS Program

11. Compile Time Statements in DATA step

12. In DATA Step

13. In PROC Steps

14. Finish one table at a time

15. Columns in your Table

Reduce Response Time16. Reduce Columns

17. Reduce Rows

18. Use Index

19. Use Views

20. Reduce Steps

21. Store numbers as characters

22. Use ELSE statement

Reduce Response Time – Course:SAS Programming 3: Advanced Techniques and Efficiencies

Names

6. Standard

7. Tabels

8. Columns

9. Formats

Make your own standard• for your self • for your department

Page 19: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

More Information

Page 20: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

SAS programs and presentationhttp://communities.sas.com/nordic

• Get the example SAS programs from today and continue your learning

• Join the Nordic SAS Online Community and receive regular activity updates

Page 21: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Webinar 7. February 2017Register here

Creating SAS code from a web browser – SAS Studio 3.6

• SAS Studio is a web based SAS programming editor.

• In this webinar we will first introduce SAS Studio and demo the basic features for creating and executing SAS programs.

• Then we will focus on relevant topics and questions related to implementing SAS studio in a real server oriented production environment.

Page 22: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Join FANS – get a membership – and then you can participate in the FANS Networking Events

Page 23: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Nordic webinar seriesSign up at www.sas.com/nordic-users

Date Title Area

January 5.1. News in SAS 9.4 M4 All

February 2.2. Efficient SAS programming Programming

7.2. SAS Studio version 3.6 Programming

28.2. Calculating values and creating parameters in SAS Visual Analytics Visual Analytics

March 17.3. SAS Environment Manager Administration, Data Management

21.3. Machine Learning with SAS Analytics

April 20.4. News from SAS Global Forum All

26.4. Graph Builder and Maps with SAS Visual Analytics Visual Analytics

May 10.5. New versions of SAS Visual Analytics Visual Analytics

45 – 60 minutes webinars. Want to request a topic? Send an e-mail: [email protected]

Note: Date and topics are preliminary. Changes can occur.

Page 24: Efficient SAS Programming · •Get the example SAS programs from today and continue your learning ... Efficient SAS programming Programming 7.2. SAS Studio version 3.6 Programming

sas.com

Copyright © SAS Inst itute Inc. A l l r ights reserved.

Contact: [email protected]