Python applications in SAS programming for medical device













- Slides: 13

Python applications in SAS programming for medical device clinical trial studies Jianlin Li, Q 2 Business Intelligence Sherry Cao, Abbott

Biography • Jianlin Li • Director of clinical data operations at Q 2 Business Intelligence (Q 2 BI) • Statistical analysis consultant at Abbott • Product quality manager and principal software engineer at Nokia • Sherry Cao • Director of Global Biometrics at Abbott Medical Device division • Leading the Statistical Reporting and Analysis Group

Improve efficiency by combining SAS and Python Clinical Trial SAS Programmers face trivial and manual operations in routine tasks, for example: • Create or clone folders in a file system • Generate batch files to execute SAS codes • Search and replace certain strings in SAS code • Convert Unicode string to support other languages • Pre-process Excel files What Python can bring to SAS programmers • General-purpose high-level language • Simple syntax rules • Powerful in manipulating text data (think “String library”) • Portable across multiple platforms (think “operating system native”)

Python is Easy to Start with • Easy to set up/install the environment and get started üInstall either Python 2 or Python 3 üInstall IDE tool (Py. Charm) for editing and running Python code • Easy to understand syntax • Easy to learn • Easy to develop • Easy to debug

Example 1: Dictionary based Unicode SAS program generation A typical workflow for generating foreign language TFLs 1. Open an English version SAS program using generic SAS 2. Open the same original SAS program using Unicode version SAS 3. Open the English TFL file 4. Open the foreign language TFL mock up file 5. Compare the English version TFLs and the Foreign language mock ups for differences and find phrases to be replaced 6. Manually update the SAS program which has been opened in Unicode SAS 7. Save the Unicode version of the SAS program 8. Repeat the above steps by hand for each SAS program in the project

Sample SAS Code • English Version • Japanese Version

Use Python to build up terminology translation dictionary • Install Python 3 compiler and Python IDE Py. Charm on MS Windows system. • Write translation dictionary in Python • Write SAS code to call the Python program to process all the SAS programs • Generate new Unicode SAS programs using the same original name and put them to a new folder • Review and make corrections on the newly generated Unicode SAS programs • Enrich the Python dictionary with the newly found Japanese phrases in the above step. • Run the SAS programs using SAS Unicode version to generate Japanese TFLs.

Dictionary Notes: • use ENCODING = 'cp 1252’ and 'utf-8' for opening input and output IO files respectively in Python 3 • SAS wrapper code to execute Python code from SAS • Similarly, a Chinese dictionary can be used for Chinese regulatory reporting projects

Example 2: Generation of batch files • Batch files are useful in orchestration of SAS program execution and redirection of List and Log files to designated locations. • Use Python to create batch files to execute ADS programs, TFL programs, and Validation programs for each study delivery. • SAS wrapper program is for SAS programmers with no technical knowledge in Python. • Special attention to text encoding üEncoding setting should be ENCODING = 'cp 1252’ üFor a foreign language project, U 8 should be set for SAS configuration (“…\nls\u 8sasv 9. cfg”) in the output batch file

Example 3: directory structures creation • Environment settings and directory structures are similar among multiple projects. • Compose a text specification file with the desired layout of file structure. • Specification file is used as a configuration file of Python program • Create SAS macro wrapper for executing Python file in SAS • Execute SAS macro

Advantages of Python-assisted SAS Programming Use case Legacy Approach Python-assisted Unicode Handling o Open SAS and SAS Unicode Version o Manual comparison o Error prone ü Centralized dictionary ü Easy to manage change and expansion ü Easy to debug Batch File Creation o Ad-hoc batch file creation o Copy and paste, error prone o Manual execution ü Systematic approach to create them ü Code inspection and quality control ü Use SAS to wrap the Python codes Folder Creation o Manual generated and manipulated o No formal recipe, can not review or QA ü Native Python code to generate folder ü Configuration file: review and QA Ø Common theme: Python makes it easy to do “Operating System”-native tasks (such as files, directories etc. ) Ø Common theme: Python’s string library (and many other libraries) is its strength

Future Potential Application: Data Management and Data Monitoring • Take advantage of a very powerful data manipulation package in Python: Pandas üUse Pandas to pre-process Excel file before data is being imported to SAS • DM programming heavily deals with Excel inputs. E. g. , üProtocol deviations üSAE integration üQuery creation üReconciliation of datasets from multiple databases • Data monitoring

Contact Information Name: Jianlin Li Company: Q 2 Business Intelligence City/State: Somerset, NJ Phone: 978 -394 -9319 Email: Jianlin. li@q 2 cro. com