When Powerful SAS Meets PowerShell TM

Similar documents
An Efficient Tool for Clinical Data Check

PharmaSUG Paper AD03

A SAS Macro Utility to Modify and Validate RTF Outputs for Regional Analyses Jagan Mohan Achi, PPD, Austin, TX Joshua N. Winters, PPD, Rochester, NY

CC13 An Automatic Process to Compare Files. Simon Lin, Merck & Co., Inc., Rahway, NJ Huei-Ling Chen, Merck & Co., Inc., Rahway, NJ

PharmaSUG Paper PO10

Reading in Data Directly from Microsoft Word Questionnaire Forms

A Macro to Create Program Inventory for Analysis Data Reviewer s Guide Xianhua (Allen) Zeng, PAREXEL International, Shanghai, China

PharmaSUG China Paper 059

A Tool to Compare Different Data Transfers Jun Wang, FMD K&L, Inc., Nanjing, China

Patricia Guldin, Merck & Co., Inc., Kenilworth, NJ USA

PharmaSUG Paper CC02

SAS Drug Development Program Portability

Regaining Some Control Over ODS RTF Pagination When Using Proc Report Gary E. Moore, Moore Computing Services, Inc., Little Rock, Arkansas

Useful Tips When Deploying SAS Code in a Production Environment

Improving Your Relationship with SAS Enterprise Guide Jennifer Bjurstrom, SAS Institute Inc.

SAS Visual Analytics Environment Stood Up? Check! Data Automatically Loaded and Refreshed? Not Quite

Copy That! Using SAS to Create Directories and Duplicate Files

Making the most of SAS Jobs in LSAF

Run your reports through that last loop to standardize the presentation attributes

ABSTRACT MORE THAN SYNTAX ORGANIZE YOUR WORK THE SAS ENTERPRISE GUIDE PROJECT. Paper 50-30

PharmaSUG Paper TT11

The Demystification of a Great Deal of Files

Using GSUBMIT command to customize the interface in SAS Xin Wang, Fountain Medical Technology Co., ltd, Nanjing, China

Journey to the center of the earth Deep understanding of SAS language processing mechanism Di Chen, SAS Beijing R&D, Beijing, China

Creating a Patient Profile using CDISC SDTM Marc Desgrousilliers, Clinovo, Sunnyvale, CA Romain Miralles, Clinovo, Sunnyvale, CA

Text Generational Data Sets (Text GDS)

PharmaSUG 2013 CC26 Automating the Labeling of X- Axis Sanjiv Ramalingam, Vertex Pharmaceuticals, Inc., Cambridge, MA

A Macro that can Search and Replace String in your SAS Programs

Using an ICPSR set-up file to create a SAS dataset

IF there is a Better Way than IF-THEN

Paper CC16. William E Benjamin Jr, Owl Computer Consultancy LLC, Phoenix, AZ

PharmaSUG China Paper 70

Let SAS Help You Easily Find and Access Your Folders and Files

Benchmark Macro %COMPARE Sreekanth Reddy Middela, MaxisIT Inc., Edison, NJ Venkata Sekhar Bhamidipati, Merck & Co., Inc.

ODS/RTF Pagination Revisit

Using SAS to Control and Automate a Multi SAS Program Process Patrick Halpin, dunnhumby USA, Cincinnati, OH

How to validate clinical data more efficiently with SAS Clinical Standards Toolkit

Automated Checking Of Multiple Files Kathyayini Tappeta, Percept Pharma Services, Bridgewater, NJ

Quick Data Definitions Using SQL, REPORT and PRINT Procedures Bradford J. Danner, PharmaNet/i3, Tennessee

Get Started Writing SAS Macros Luisa Hartman, Jane Liao, Merck Sharp & Dohme Corp.

Not Just Merge - Complex Derivation Made Easy by Hash Object

The Next Generation Smart Program Repository

A Mass Symphony: Directing the Program Logs, Lists, and Outputs

PhUSE US Connect 2019

TLFs: Replaying Rather than Appending William Coar, Axio Research, Seattle, WA

TLF Management Tools: SAS programs to help in managing large number of TLFs. Eduard Joseph Siquioco, PPD, Manila, Philippines

Applications Development. Paper 38-28

The new SAS 9.2 FCMP Procedure, what functions are in your future? John H. Adams, Boehringer Ingelheim Pharmaceutical, Inc.

Using UNIX Shell Scripting to Enhance Your SAS Programming Experience

Automation of makefile For Use in Clinical Development Nalin Tikoo, BioMarin Pharmaceutical Inc., Novato, CA

PharmaSUG Paper CC22

The Output Bundle: A Solution for a Fully Documented Program Run

A SAS Macro to Generate Caterpillar Plots. Guochen Song, i3 Statprobe, Cary, NC

Simplifying Your %DO Loop with CALL EXECUTE Arthur Li, City of Hope National Medical Center, Duarte, CA

esubmission - Are you really Compliant?

Chasing the log file while running the SAS program

Submitting SAS Code On The Side

SAS automation techniques specification driven programming for Lab CTC grade derivation and more

SAS ENTERPRISE GUIDE USER INTERFACE

Qlik Sense Cmdlet for PowerShell. Sokkorn CHEAV

Tips and Fixes for Cross-Environment Batch Transfer of SAS Data

Step through Your DATA Step: Introducing the DATA Step Debugger in SAS Enterprise Guide

Sending Text Messages from SAS

AD07 A Tool to Automate TFL Bundling

Paper ###-YYYY. SAS Enterprise Guide: A Revolutionary Tool! Jennifer First, Systems Seminar Consultants, Madison, WI

Paper A Simplified and Efficient Way to Map Variable Attributes of a Clinical Data Warehouse

Powershell: Introduction and Practical Uses. Presentation URL:

An Alternate Way to Create the Standard SDTM Domains

Importing CSV Data to All Character Variables Arthur L. Carpenter California Occidental Consultants, Anchorage, AK

Preparing the Office of Scientific Investigations (OSI) Requests for Submissions to FDA

A Macro To Generate a Study Report Hany Aboutaleb, Biogen Idec, Cambridge, MA

Create a Format from a SAS Data Set Ruth Marisol Rivera, i3 Statprobe, Mexico City, Mexico

Macro Method to use Google Maps and SAS to Geocode a Location by Name or Address

SAS Data Integration Studio Take Control with Conditional & Looping Transformations

Enterprise Guide Version 2.0 for Windows

Real Time Clinical Trial Oversight with SAS

Migration to SAS Grid: Steps, Successes, and Obstacles for Performance Qualification Script Testing

Your Own SAS Macros Are as Powerful as You Are Ingenious

Microsoft Windows PowerShell v2 For Administrators

The Submission Data File System Automating the Creation of CDISC SDTM and ADaM Datasets

PharmaSUG Paper AD09

Why SAS Programmers Should Learn Python Too

Write SAS Code to Generate Another SAS Program A Dynamic Way to Get Your Data into SAS

for Western Users of SAS Software 2014

Lab CTCAE the Perl Way Marina Dolgin, Teva Pharmaceutical Industries Ltd., Netanya, Israel

Exploring the SAS Macro Function %SYSFUNC

SDTM Attribute Checking Tool Ellen Xiao, Merck & Co., Inc., Rahway, NJ

An Efficient Method to Create Titles for Multiple Clinical Reports Using Proc Format within A Do Loop Youying Yu, PharmaNet/i3, West Chester, Ohio

ABSTRACT: INTRODUCTION: WEB CRAWLER OVERVIEW: METHOD 1: WEB CRAWLER IN SAS DATA STEP CODE. Paper CC-17

Hands-Off SAS Administration Using Batch Tools to Make Your Life Easier

PDF Multi-Level Bookmarks via SAS

Application Interface for executing a batch of SAS Programs and Checking Logs Sneha Sarmukadam, inventiv Health Clinical, Pune, India

A Taste of SDTM in Real Time

One Project, Two Teams: The Unblind Leading the Blind

Streamline Table Lookup by Embedding HASH in FCMP Qing Liu, Eli Lilly & Company, Shanghai, China

Quick Results with the Output Delivery System

Someone Changed My SAS Visual Analytics Report! How an Automated Version Control Process Can Rescue Your Report and Save Your Sanity

Easy CSR In-Text Table Automation, Oh My

What Do You Mean My CSV Doesn t Match My SAS Dataset?

Using Unnamed and Named Pipes

Transcription:

PharmaSUG 2018 - Paper QT-06 When Powerful SAS Meets PowerShell TM Shunbing Zhao, Merck & Co., Inc., Rahway, NJ, USA Jeff Xia, Merck & Co., Inc., Rahway, NJ, USA Chao Su, Merck & Co., Inc., Rahway, NJ, USA ABSTRACT PowerShell is an MS Windows-based command shell for direct interaction with an operating system and its task automation. When combining the powerful SAS programming language and PowerShell commands/scripts, we can greatly improve our efficiency and accuracy by removing many trivial manual steps in our daily routine work as SAS programmers. This paper presents five applications we developed for process automation. 1) Automatically convert RTF files in a folder into PDF files, all files or a selection of them. Installation of Adobe Acrobat printer is not a requirement. 2) Search the specific text of interest in all files in a folder, the file format could be RTF or SAS Source code. It is very handy in situations like meeting urgent FDA requests when there is a need to search required information quickly. 3) Systematically back up all existing files including the ones in subfolders. 4) Update the attributes of a selection of files with ease, i.e., change all SAS code and their corresponding output including RTF tables and SAS log in a production environment to read only after database lock. 5) Remove hidden temporary files in a folder. It can clean up and limit confusion while delivering the whole output folder. Lastly, the SAS macros presented in this paper could be used as a starting point to develop many similar applications for process automation in analysis and reporting activities. INTRODUCTION Windows PowerShell is a MS Windows-based command shell that provides automation capabilities to end users. Many trivial manual steps in file management could be eliminated by using this valuable utility. SAS provides users the capability to call PowerShell commands by using FILENAME PIPE syntax, or to create a script to run by using DATA OUTPUT. When combining the powerful SAS programming language with PowerShell s rich scripting language, we are able to improve the efficiency and accuracy greatly by eliminating many trivial manual steps in our daily routine work as SAS programmers. To promote the usage of PowerShell in SAS users, Chris Hemedinger from SAS Institute provided a few useful examples in an official blog to explain how to combine SAS with Windows PowerShell. This paper presents five scenarios of using SAS to call PowerShell functions, which can be served as a starting point to get benefits from both PowerShell and SAS for SAS programmers in the pharmaceutical industry. DISCUSSION Firstly, SAS must have access to the PowerShell. Various shortcuts are found in Start > All Programs > Accessories > Windows PowerShell. After PowerShell window appears, the user has to run the following commands to update some security policy: Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. The PowerShell Command/Script is now effectively enabled. Scenario 1 A batch of RTF files are requested to be converted into PDF files and delivered to customers. A macro (some key part) for this task was developed as shown below. 1

%macro ps0rtf2pdf( in_path=,out_path=,rtfname= ) / minoperator; * Generate PowerShell Script; %put NOTE-Generating Powershell Script &workdir\_rtf2pdf.ps1; length line $255 len 8; file "&workdir\_pstemp.ps1" lrecl=255; put " "; line = "$word_app = New-Object -ComObject Word.Application"; line = "Get-ChildItem -Path &in_path -Filter &rtfname..rtf ForEach-Object {"; line = "$document = $word_app.documents.open($_.fullname)"; line = "$pdf_filename = ""&out_path.\$($_.basename).pdf"""; line = "$Document.ExportAsFixedFormat($pdf_filename,17,$false,1,0,0,0,0,$true,$true,1,$true,$true,$false)"; line = "$document.close()}"; line = "$word_app.quit()"; * Executing Script; x powershell -file "&workdir\_pstemp.ps1" ""; %mend ps0rtf2pdf; Using this macro, a group of selective RTF files can be converted into PDF files with bookmarks kept automatically. Figure 1 shows one example of the application of this macro. 2

Figure 1. Screenshot of an application to automatically convert RTF files into PDF files in a folder. Scenario 2 In SAS programs, search is needed to be applied to check whether a certain ADaM dataset is used or a certain SAS proc is executed. It is especially necessary in urgent situations such as meeting FDA requests for searching required information quickly. The SAS program below can help to complete this task easily. %let loc=c:\pstest\; %let path=c:\pstest\macrolib; %let file=testall.txt; %let pattern=%str(\b\w+\b.adtte); %let file_type=sas; options noquotelenmax; filename process pipe "powershell -Command ""get-childitem -path &path -filter *.&file_type - recurse select-string -pattern &pattern format-table path, linenumber, line -Auto Out-File &loc.&file -width 512"""; infile process lrecl=600; In the program codes above, a regular expression can be assigned to the pattern and the PowerShell command is compatible with the regular expression. It provides more flexibility to our search program. Figure 2 demonstrates one exemplary result in which programs are found where ADTTE was referenced. Figure 2. Screenshot of the searching result in all SAS files in a folder: regular expression pattern=%str(\b\w+\b\.adtte) 3

Scenario 3 It is necessary to systematically back up all existing files, including the ones in the subfolders. The below macro could be very handy and efficient in such a case. See below for the key part of the macro. %macro ps0backup( root_path=,sub_lst= ) / minoperator; * Generate PowerShell Script; %put NOTE-Generating Powershell Script &root_path\_ps0bk.ps1; length line $255 len 8; file "&root_path\_ps0bk.ps1" lrecl=255; put " "; line = "Param([Parameter(Mandatory=$true)][Alias('sf')][String]$subfolder)"; line = "$source = ""&root_path.\$subfolder"""; line = "$date=get-date -f yyyy-mm-ddthh-mm-ss"; line = "new-item -path $source -type directory -name $date"; line = "robocopy $source $source\$date "; * Executing Script; %let totsub=%sysfunc(countw(&sub_lst,%str( ))); %do i=1 %to &totsub; %let subfolder=%scan(&sub_lst,&i,%str( )); %let root_path_=&root_path\&subfolder; %if %sysfunc(fileexist(&root_path_)) > 0 %then %do; x powershell.exe -file %superq(root_path)\_ps0bk.ps1 - sf %superq(subfolder); %else %do; %put &err1&err2: Specified subfolder, &root_path_, does not exist; x powershell.exe -command Remove-Item "%superq(root_path)\_ps0bk.ps1"; %mend ps0backup; Figure 3 gives one example of calling 4

%ps0backup( root_path=c:\pstest,sub_lst= ); Figure 3. Screenshot of an application to systematically back up all existing files in subfolders with names in the date format. Scenario 4 We need to change all SAS codes and their corresponding outputs including RTF tables and SAS logs in a production environment to read-only after the database lock. The below macro (only key parts are shown) will assist us to update the attributes of a selection of files. %macro ps0readonly( root_path=,sub_lst=,type= ) / minoperator; %let totsub=%sysfunc(countw(&sub_lst,%str( ))); %do i=1 %to &totsub; %let subvar=%scan(&sub_lst,&i,%str( )); 5

%let root_path_=&root_path\&subvar; %if %sysfunc(fileexist(&root_path_)) > 0 %then %do; %if %length(&type) eq 0 %then %do; x powershell.exe -command Set-ItemProperty -Path "%superq(root_path_)\*.*" -Name IsReadOnly -Value $True; %else %do; x powershell.exe -command Set-ItemProperty -Path "%superq(root_path_)\*.%superq(type)" -Name IsReadOnly -Value $True; %else %do; %put &err1&err2: Specified subfolder, &root_path_, does not exist; %mend ps0readonly; Scenario 5 Removing any hidden temporary files in a folder is required. It can eliminate confusion while delivering the whole output folder. The below SAS program can help us to accomplish this task easily. %let path=c:\pstest\outtable; %let pattern=%str(~$*.rtf); options noquotelenmax; filename process pipe "powershell -Command ""get-childitem -path &path -filter &pattern -force - recurse remove-item -force"""; infile process lrecl=500; CONCLUSION As SAS programmers, we can improve our efficiency and accuracy greatly by eliminating many trivial manual steps in our daily routine work when starting PowerShell from SAS. SAS macros presented in this paper can help other users develop many similar applications for process automation in analysis and reporting activities. REFERENCES Chris Hemedinger SAS online Communities Blog. ACKNOWLEDGMENTS The authors would like to thank Cynthia He and Nancy Meng for their great support and valuable input to this paper. CONTACT INFORMATION Your comments and questions are valued and encouraged. Contact the authors at: 6

Name: Shunbing Zhao Enterprise: Merck Address: 126 E. Lincoln Avenue City, State ZIP: Rahway, NJ 07065-4607 Work Phone: 732-594-3976 Fax: E-mail: shunbing.zhao@merck.com Web: www.merck.com Name: Jeff Xia Enterprise: Merck Address: 126 E. Lincoln Avenue City, State ZIP: Rahway, NJ 07065-4607 Work Phone: 732-594-6439 Fax: E-mail: jeff.xia@merck.com Web: www.merck.com Name: Chao Su Enterprise: Merck Address: 126 E. Lincoln Avenue City, State ZIP: Rahway, NJ 07065-4607 Work Phone: 732-594-6459 Fax: E-mail: chao.su@merck.com Web: www.merck.com 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 registered trademarks or trademarks of their respective companies. 7