8
1 PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming Shefalica Chand, Seattle Genetics, Inc., Bothell, WA ABSTRACT Efficient SAS® programming is one of the keys to success for SAS® programmers and in-turn to their organizations. SAS® programmers are always looking for tips and tricks to make their job more effective and less time consuming, without compromising on the quality. This saved time and resources can then be utilized in learning new skill sets, improving existing processes and many other infrastructure development ideas and initiatives. TextPad® is one such simple tool; when used in conjunction with SAS®, it can do wonders. This paper sheds light on aspects of using TextPad® for efficient SAS® (Statistical/Clinical) Programming techniques. Some of the utilities of TextPad® that will be discussed in this paper are as below: Executing SAS® from TextPad® and creating “Run SAS” button in the Toolbar Viewing multiple files (SAS, LST, LOG) Creating quick tags and shortcuts using TCL files Comparison of multiple files (SAS, LST, LOG) Synchronize scrolling to facilitate manual comparison Quick fix indentations by block selection Search text string features: “Find” and “Find in files” options Accessing direct links to SAS® programs, in search results of “Find in files” option Replacing text strings in one or more files Color coding, to identify keywords of concern (Example: WARNING, ERROR, UNINTIALIZED, MISSING, etc.) INTRODUCTION The clinical research industry is moving at an astonishing pace with sponsors having dense pipelines, continuously introducing newer products and formulas, to improve patient’s lives. This means SAS® programmers are expected to deliver analysis results faster and at the same time ensure quality and accuracy of the results. Seasoned SAS® programmers are constantly striving to look for tips, tricks and tools to take their efficiency, multi-tasking and time management skills to new heights. This paper will introduce to the SAS® users many features found in TextPad® that can be used as a SAS® editor to make more efficient use of time and resources. This paper will also give step-by- step instructions of setting-up TextPad® Editor for SAS® execution, using various features of TextPad® to minimize manual intervention in SAS® code editing, file comparison, batch changes in programs, find and search options, visually identifying alert messages in the log file in attempt to streamline SAS® programming process and reduce resource consumption. INSTALLING TEXTPAD® ON YOUR MACHINE TextPad® can easily be downloaded from www.textpad.com. Once we are on the website we may follow simple instructions from the website to download the free software (The download instructions will not be discussed in this paper). SYNTAX DEFINITION FILES .SYN (ADD-ONS) From the www.textpad.com two files with .syn extension need to be downloaded and saved in a particular location on the C Drive of the machine. The two files are sas4.syn and log.syn that can be downloaded from Download->Add- on->Syntax Definitions. These files help with color coding .sas, .bat, .tcl and .log files.

PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

1

PharmaSUG 2015 – Paper QT20

Simplicity is the Soul of Efficiency:

Simple Tips and Tricks for Efficient SAS® Programming

Shefalica Chand, Seattle Genetics, Inc., Bothell, WA

ABSTRACT

Efficient SAS® programming is one of the keys to success for SAS® programmers and in-turn to their organizations. SAS® programmers are always looking for tips and tricks to make their job more effective and less time consuming, without compromising on the quality. This saved time and resources can then be utilized in learning new skill sets, improving existing processes and many other infrastructure development ideas and initiatives. TextPad® is one such simple tool; when used in conjunction with SAS®, it can do wonders.

This paper sheds light on aspects of using TextPad® for efficient SAS® (Statistical/Clinical) Programming techniques.

Some of the utilities of TextPad® that will be discussed in this paper are as below:

• Executing SAS® from TextPad® and creating “Run SAS” button in the Toolbar

• Viewing multiple files (SAS, LST, LOG)

• Creating quick tags and shortcuts using TCL files

• Comparison of multiple files (SAS, LST, LOG)

• Synchronize scrolling to facilitate manual comparison

• Quick fix indentations by block selection

• Search text string features: “Find” and “Find in files” options

• Accessing direct links to SAS® programs, in search results of “Find in files” option

• Replacing text strings in one or more files

• Color coding, to identify keywords of concern (Example: WARNING, ERROR, UNINTIALIZED, MISSING,

etc.)

INTRODUCTION

The clinical research industry is moving at an astonishing pace with sponsors having dense pipelines, continuously introducing newer products and formulas, to improve patient’s lives. This means SAS® programmers are expected to deliver analysis results faster and at the same time ensure quality and accuracy of the results. Seasoned SAS® programmers are constantly striving to look for tips, tricks and tools to take their efficiency, multi-tasking and time management skills to new heights. This paper will introduce to the SAS® users many features found in TextPad® that can be used as a SAS® editor to make more efficient use of time and resources. This paper will also give step-by-step instructions of setting-up TextPad® Editor for SAS® execution, using various features of TextPad® to minimize manual intervention in SAS® code editing, file comparison, batch changes in programs, find and search options, visually identifying alert messages in the log file in attempt to streamline SAS® programming process and reduce resource consumption.

INSTALLING TEXTPAD® ON YOUR MACHINE TextPad® can easily be downloaded from www.textpad.com. Once we are on the website we may follow simple instructions from the website to download the free software (The download instructions will not be discussed in this paper).

SYNTAX DEFINITION FILES .SYN (ADD-ONS) From the www.textpad.com two files with .syn extension need to be downloaded and saved in a particular location on the C Drive of the machine. The two files are sas4.syn and log.syn that can be downloaded from Download->Add-on->Syntax Definitions. These files help with color coding .sas, .bat, .tcl and .log files.

Page 2: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

2

SAS® Files Copy file sas4.syn to C:\Program Files (x86)\TextPad 7\system

• Open TextPad® and click on Configure->New document class. This will open a document class "wizard"

• Give the new class the name “SAS” and click next

• Enter “*.sas, *.bat, *.tcl” for the class member and click next

• Check the box "enable syntax highlighting" and choose sas4.syn from the drop-down list for the syntax definition file, then click next.

• Click finish

Log Files Copy file log.syn to C:\Program Files (x86)\TextPad 7\system

• Open TextPad® and click on Configure->New document class. This will open a document class "wizard"

• Give the new class the name “Log Files” and click next

• Enter *.log for the class member and click next

• Check the box "enable syntax highlighting" and choose log.syn from the drop-down list for the syntax definition file, then click next.

• Click finish

EXECUTING SAS® FROM TEXTPAD® AND CREATING “RUN SAS” BUTTON IN THE TOOLBAR TextPad® can be customized to create a “Run SAS” Button in the Toolbar, to execute SAS® programs from TextPad® editor itself. How to execute SAS® from TextPad®

• Go to Configure->Preferences->Tools

• Click on Add and select “DOS Command…”

• Name it “Run SAS” and hit Apply

• Go back to “Tools” and then click on “Run SAS”

• The window will look similar to screenshot in Figure 1,

where Parameters = "C:\Program Files\SASHome\x86\SASFoundation\9.3\SAS.exe" $BaseName –

nosplash

How to have the Tool “Run SAS” Displayed on the Toolbar of TextPad

• Go to View-> Toolbars->Tools

• It will display all the standard tools; however we don’t need all of them

• Click on the down arrow to “Add or Remove Buttons” and then “Tools”. Check only the required tools (in

this case it will be “Tool 1”)

(a) (b)

Figure 1. (a) Preferences window and (b) Screenshot Tools dropdown

Page 3: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

3

VIEWING MULTIPLE FILES (SAS, LST, LOG) TextPad® enables viewing multiple files of different nature at the same time. The setting can be controlled from View-> Document Selector or View-> Document Tabs

CREATING QUICK TAGS AND SHORTCUTS USING TCL FILES

TextPad® package comes with several standard Tcl (Tool Command Language) files. Example- ansichar.tcl, ctrlchar.tcl, doschar.tcl, htmltags.tcl, htmlchar.tcl, SMS.tcl. These files have various functions and can be found in the Samples folder C:\Program Files (x86)\TextPad 7\Samples. These files can be viewed or used from View-> Clip Library, which will open a Clip Library window. These files are quick access to embed program script, into the code. A custom Tcl files can be created, that may contain short cuts and tags to most commonly used SAS® codes/procedures or other standard text strings like programmer header, acceptable commenting style, author’s name etc. Here is an example of a Tcl file scripted for Program Header, Open Code Comment and Proc Transpose Syntax

!TCL=6001, Short Cuts Clipbook library for Textpad. 2002, Seattle Genetics Inc.

!TITLE=ShortCuts

!SORT=N

!TEXT=Program Header

/*--------------------------- Seattle Genetics Standard Program Header ----------------------*

| Program Name:

| Operating System(s):

| SAS Version:

| Author:

| Purpose:

|

| Inputs Path\Name(s):

|

| Outputs Path\Name(s):

|

|---------------------------------------- Macro Programs -------------------------------------

| Intended Macro Usage:

| Dependencies:

| Restrictions:

| --- Macro Parameters : Parameter Description ---

|

|------------------------------ Post-Testing Modifications History ---------------------------

| Mod. Date User Name Modification

|

|-------------------------------------------------------------------------------------------*/

!

!TEXT=Open Code Comment

*-----------------------------------------------------*

| Flower box

*-----------------------------------------------------*;

!

!TEXT=Proc Transpose

PROC TRANSPOSE <DATA=input-data-set> <DELIMITER=delimiter> <LABEL=label> <LET>

<NAME=name> <OUT=output-data-set> <PREFIX=prefix> <SUFFIX=suffix>;

BY <DESCENDING> variable-1

<...<DESCENDING> variable-n>

<NOTSORTED>;

COPY variable(s);

ID variable;

IDLABEL variable;

VAR variable(s);

RUN;

!

Page 4: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

4

Once the Tcl file is saved in the Samples folder, it automatically appears in the Clip Library dropdown list. Selecting the Tcl file will take us to another dropdown list, from where required shortcuts can be accessed by clicking on them.

(a) (b) Figure 2. (a) Clip Library dropdown and (b) Using shortcuts from Tcl File

COMPARISON OF MULTIPLE FILES (SAS, LST, LOG)

Multiple files can be compared using Compare files feature ( From Toolbar) When we use this option, we get an opportunity to select our choice to ignore differences due to 1) Upper and lower case letters and 2) Number of spaces or tabs. The result of comparison utility will be displayed in “Tool Output” window differentiated by (<) and (>) operators.

(a) (b) Figure 3. (a) Compare Text Files window and (b) Comparison results in Tool Output window

SYNCHRONIZE SCROLLING TO FACILITATE MANUAL COMPARISON Sometimes we want to do a manual comparison by visually reviewing two files side-by-side (or even multiple files). TextPad® does have a feature to facilitate this by Synchronize scrolling (From Configure Menu) First, we want to tile the two files in a way we would like to view them, from Window option in the Toolbar. The next step would be to choose Synchronize option from Configure ->Synchronize Scrolling.

Page 5: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

5

Figure 4. Window tiling options Now the selected files will scroll together at the same pace, when controlled by arrow buttons or mouse.

QUICK FIX INDENTATIONS BY BLOCK SELECTION Correct indentation is the key to efficient programming. It helps with clarity in reading, understanding and debugging a program. This is especially useful in macro coding or programs with multiple do loops. At times, it becomes tedious to fix the indentation line by line. TextPad® helps do this task easily by using Block Selection feature. Right click in the program window to activate Block Select Mode. Once this is done, we can start selecting blocks of code. In the example below there are 2 extra blank spaces in lines 3, 4, 5, which makes it difficult to read the code. Block selection can help select a block to 2 spaces horizontally and 3 lines vertically. We may then delete all these extra spaces in one go.

(a) (b)

Figure 5. (a) Block Selection and (b) Updated program Note that in Figure 4(b) an asterisk appears right next to the program name Macro1.sas*, which indicates that the program has been edited however has not been re-saved yet.

SEARCH TEXT STRING FEATURES: “FIND” AND “FIND IN FILES” OPTIONS There are two kinds of Find features that TextPad® offers.

1. Find a text string in the active program. This can be done by Search->Find or clicking from the Toolbar

2. Find a text string in one or multiple programs, in a particular folder. This can be done by Search->Find in Files

or by clicking from the Toolbar

Page 6: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

6

(a) (b)

Figure 6. (a) Find search for active programs and (b) “Find in Files” search in files in a folder There are plenty of other options within each Find feature that can be utilized to enhance or narrow down the search criteria.

ACCESSING DIRECT LINKS TO SAS® PROGRAMS, IN SEARCH RESULTS OF “FIND IN FILES” OPTION The search results of “Find in Files” are dynamic and are very useful. For example, we are looking for a keyword text string “prodcut”. The results of “Find in Files” will be displayed in “Search Results” window.

Figure 7. Find in Files search results These search results are actually dynamic links, which means we can open those programs by just double clicking on the search results directly. This is very helpful in making further changes in those specific programs.

REPLACING TEXT STRINGS IN ONE OR MORE FILES TextPad® has a feature of replacing text strings in one or more files at the same time. Continuing from the above example in Figure 6, suppose we realized that the keyword “product” had been misspelt in a few programs as “prodcut”. We are not sure how many programs have been affected. In this scenario, we may use the Find in Files

Page 7: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

7

feature to find the occurrence of the keyword. We can now open all the affected programs by double clicking each occurrence in search results and then we may do a mass change by replace feature from Search->Replace or

clicking from the Toolbar.

Figure 8. Replace option We may even choose to replace the text in Active document or All open documents.

COLOR CODING, TO IDENTIFY KEYWORDS OF CONCERN (EXAMPLE: WARNING, ERROR, UNINTIALIZED, MISSING, ETC.) Earlier, we talked about the syntax definition files .syn. This feature can further be enhanced to highlight keywords of interest. This is especially helpful when programmers are viewing or scanning the files, example log files, to instantly identify the keywords of concern. This can be done from the Preferences -> Document Classes -> Log Files -> Colors. We can set a foreground and background of our choice with eye-catching colors.

Figure 9. Color coding keywords of concern/interest

CONCLUSION

As such, TextPad® is a very simple tool, however with some additional enhancements it can become a dynamic editor that can work with SAS® to add efficiency to SAS® programming skills. The time saved with these enhanced attributes are tremendous, which will in-turn help SAS® programmers to use the saved time and resources for other process improvement ideas and help their organization and industry grow to new heights.

ACKNOWLEDGMENTS

I would like to thank Rajeev Karanam for his valuable suggestions and comments.

Page 8: PharmaSUG 2015 – Paper QT20 Simplicity is the Soul of … · 2015-05-14 · Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

Simplicity is the Soul of Efficiency: Simple Tips and Tricks for Efficient SAS® Programming, continued

8

Contact Information

Your comments and questions are valued and encouraged. Contact the authors at:

Shefalica Chand Seattle Genetics, Inc. 21823 - 30th Drive S.E. Bothell, WA 98021 425-527-4866 [email protected]

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.

Other brand and product names are trademarks of their respective companies.