How To Create An Audit Trail In Sas



Similar documents
Integrity Constraints and Audit Trails Working Together Gary Franklin, SAS Institute Inc., Austin, TX Art Jensen, SAS Institute Inc.

ing Automated Notification of Errors in a Batch SAS Program Julie Kilburn, City of Hope, Duarte, CA Rebecca Ottesen, City of Hope, Duarte, CA

How to monitor AD security with MOM

PharmaSUG Paper AD11

REx: An Automated System for Extracting Clinical Trial Data from Oracle to SAS

Optional Lab: Data Backup and Recovery in Windows 7

Technical Paper. Defining an ODBC Library in SAS 9.2 Management Console Using Microsoft Windows NT Authentication

Lab - Data Backup and Recovery in Windows 7

Paper PO03. A Case of Online Data Processing and Statistical Analysis via SAS/IntrNet. Sijian Zhang University of Alabama at Birmingham

We begin by defining a few user-supplied parameters, to make the code transferable between various projects.

Installation Instructions for Hot Fix I92003

CHAPTER 1 Overview of SAS/ACCESS Interface to Relational Databases

Best Practices for Disaster Recovery with Symantec Endpoint Protection

Data Presentation. Paper Using SAS Macros to Create Automated Excel Reports Containing Tables, Charts and Graphs

Improving Your Relationship with SAS Enterprise Guide

You have got SASMAIL!

SQL Server Protection

Same Data Different Attributes: Cloning Issues with Data Sets Brian Varney, Experis Business Analytics, Portage, MI

Using SAS to Control and Automate a Multi SAS Program Process. Patrick Halpin November 2008

SQL Server Protection Whitepaper

Search and Replace in SAS Data Sets thru GUI

Introduction to SAS on Windows

Achieving PCI COMPLIANCE with the 2020 Audit & Control Suite.

Using Macros to Automate SAS Processing Kari Richardson, SAS Institute, Cary, NC Eric Rossland, SAS Institute, Dallas, TX

NETWRIX FILE SERVER CHANGE REPORTER

Specific Information for installation and use of the database Report Tool used with FTSW100 software.

AN INTRODUCTION TO MACRO VARIABLES AND MACRO PROGRAMS Mike S. Zdeb, New York State Department of Health

Customized Excel Output Using the Excel Libname Harry Droogendyk, Stratia Consulting Inc., Lynden, ON

CANADA SAVINGS BONDS WEB TRANSMISSION GUIDE csb.gc.ca PAYROLL SAVINGS PROGRAM 20$ 40$ 80$ 50 $ 30$ WEBGUIDE-14

Optional Lab: Data Backup and Recovery in Windows Vista

Remove Orphan Claims and Third party Claims for Insurance Data Qiling Shi, NCI Information Systems, Inc., Nashville, Tennessee

AVDC Document Management System Getting Started

AN ANIMATED GUIDE: SENDING SAS FILE TO EXCEL

SPHOL207: Database Snapshots with SharePoint 2013

How to Back Up and Restore an ACT! Database Answer ID 19211

Moving Files from TSO to a PC

Moving the TRITON Reporting Databases

# or ## - how to reference SQL server temporary tables? Xiaoqiang Wang, CHERP, Pittsburgh, PA

SAS Credit Scoring for Banking 4.3

ABSTRACT THE ISSUE AT HAND THE RECIPE FOR BUILDING THE SYSTEM THE TEAM REQUIREMENTS. Paper DM

SolidWorks Enterprise PDM and FDA 21CFR Part 11

Moving the Web Security Log Database

StruxureWare Power Monitoring 7.0. Side By Side Upgrade Guide For Distributed Systems

A SAS Based Correspondence Management System Bernd E. Imken, Patented Medicine Prices Review Board, Ottawa, Canada

Backup and Restore with 3 rd Party Applications

Installation Manual Version 8.5 (w/sql Server 2005)

Get in Control! Configuration Management for SAS Projects John Quarantillo, Westat, Rockville, MD

Reflection DBR USER GUIDE. Reflection DBR User Guide. 995 Old Eagle School Road Suite 315 Wayne, PA USA

Automated distribution of SAS results Jacques Pagé, Les Services Conseils HARDY, Quebec, Qc

1 of 10 1/31/2014 4:08 PM

Restoring Microsoft SQL Server 7 Master Databases

Microsoft SQL Server Guide. Best Practices and Backup Procedures

The Advantages of Using RAID

SUGI 29 Data Warehousing, Management and Quality

Overview. NT Event Log. CHAPTER 8 Enhancements for SAS Users under Windows NT

How to protect, restore and recover SQL 2005 and SQL 2008 Databases

Writing Data with Excel Libname Engine

Lab - Data Backup and Recovery in Windows Vista

STATISTICA VERSION 9 STATISTICA ENTERPRISE INSTALLATION INSTRUCTIONS FOR USE WITH TERMINAL SERVER

PROC SQL for SQL Die-hards Jessica Bennett, Advance America, Spartanburg, SC Barbara Ross, Flexshopper LLC, Boca Raton, FL

How to restore a Microsoft SQL Server Master Database with Backup Exec for Windows Servers (Automate Master Database Restore)

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

STIDistrict SQL 2000 Database Management Plans

Managing Custom Data Standards in SAS Clinical Data Integration

SEER Enterprise Shared Database Administrator s Guide

Restoring Sage Data Sage 200

VMware and VSS: Application Backup and Recovery

Using Pharmacovigilance Reporting System to Generate Ad-hoc Reports

HansaWorld SQL Training Material

Modular Messaging. Release 4.0 Service Pack 4. Whitepaper: Support for Active Directory and Exchange 2007 running on Windows Server 2008 platforms.

Backup Notification in Client Profiles for Windows

John D. Bonam Disaster Recovery Architecture Session # 2841

Full Compliance Contents

Microsoft Dynamics GP Audit Trails

If you have questions or need assistance, contact PCS Technical Services using the contact information on page 10.

Backup and Restore of CONFIGURATION Object on Windows 2008

MapGuide Open Source Repository Management Back up, restore, and recover your resource repository.

Managing and Maintaining a Microsoft Windows Server 2003 Environment

Analyzing the Server Log

Importing Excel File using Microsoft Access in SAS Ajay Gupta, PPD Inc, Morrisville, NC

Order from Chaos: Using the Power of SAS to Transform Audit Trail Data Yun Mai, Susan Myers, Nanthini Ganapathi, Vorapranee Wickelgren

Download Path for 7 Zip : ( Username & Password to download = sqlutility ) **Make sure install the right one or else you can t find 7 Zip to Extract.

Lab: Data Backup and Recovery in Windows XP

Choosing the Best Method to Create an Excel Report Romain Miralles, Clinovo, Sunnyvale, CA

Backup Exec Private Cloud Services. Planning and Deployment Guide

SUGI 29 Applications Development

How To Use Sas With A Computer System Knowledge Management (Sas)

EMC Documentum Repository Services for Microsoft SharePoint

NE-2273B Managing and Maintaining a Microsoft Windows Server 2003 Environment

MOUNT10 Plug-ins. V7 Sailfish R2 User Manual. for Microsoft Windows. Your guide to installing and using MOUNT10 plug-ins.

Upgrade Guide BES12. Version 12.1

Library Recovery Center

Transcription:

Audit Trails for SAS Data Sets Minh Duong Texas Institute for Measurement, Evaluation, and Statistics University of Houston, Houston, TX ABSTRACT SAS data sets are now more accessible than ever. They are commonly stored on network shared folders and accessed by many different users. Tracking when modifications were made, who made the modifications and why is an increasing challenge. Without a system to log modification you might be compromising the quality of your data. Audit trails can be used to help solve this problem. INTRODUCTION Audit trails track modifications and gives you the ability to restore records. The Audit Trail is an optional SAS file that can be created to log modifications to a SAS data file. Every time a record is added, deleted, or updated, information is written to the audit trail about who made the modification, what was modified, and when. Audit trails contain all the changes to the data set, this allows you the ability to fix unintended changes and restore to an earlier version of the data. Since historical information about the data is maintained, you can also develop statistics and patterns. Audit trails will also store observations from failed append operations that were rejected by integrity constraints. The audit trail also enables you to write a DATA step to extract the failed or rejected observation and then reapply the observation to the data file. The audit trail is created by the default Base SAS engine and has the same member name as the data file but set type of AUDIT. It replicates the variables in the data set and adds _AT*_ variables and user variables. Below are the variables in the audit trail and code values. _AT*_ variables are the table below. _ATDATETIME ATUSERID ATOBSNO ATRETURNCODE ATMESSAGE ATOPCODE_ Stores the date and time of a modification Stores the logon user ID that is associated with a modification Stores the observation number that is affected by the modification, except when REUSE=YES (because the observation number is always 0) Stores the event return code Stores the SAS log message at the time of the modification Stores a code that describes the type of modification

_ATOPCODE_ code values are below AL AS DA DD DR DW EA ED EU Auditing is resumed Auditing is suspended Added data record image Deleted data record image Before update record image After update record image Observation add failed Observation delete failed Observation update failed INITIATE AUDIT TRAIL Let s do an example. First we create a libname to a temporary directory and copy the sashelp.class data set to the temporary location. Then we create an audit trail for the SAS data set using the code below. An optional user variable _reason_change_ is added to the audit trail. User variables can be used to capture reasons for a modifications or any other information. libname mydata "c:\era\"; set sashelp.class; proc datasets lib=mydata; audit class; initiate; user_var _reason_change_ $30; quit; Suspend, resume, and terminate are other options for the audit statement. The suspend option stops the event logging but does not delete the audit trail. Resume resumes the event logging after the audit trail was suspended. Terminate stops the event logging and deletes the audit trail. We can see the status of the data set by running proc contents. Figure 1 shows the output of the proc contents. proc contents data=mydata.class(type=audit);

Figure 1. Output of proc contents of audit trail. Now let s modify the data set and see the audit trail in action. We run the code below to modify the data set. The first data step will modify John s age to 22. The next will insert a new record into the data set and the third will delete a record from the data set. We set _reason_change_ to the reason for the modification. This will be retained in the audit trail and can be referenced later by viewing the audit table. modify mydata.class; where name = "John"; age = "22"; _reason_change_ = "correct John's age"; proc sql; insert into mydata.class set name = "Minh", sex = "M", Age = 30,

Weight = 175, Height = 66, _reason_change_ = "Moved to school"; quit; modify mydata.class; where name = "William"; remove; Now that the modifications have been made we can see what the audit trail looks like. We run the code below to create a data set from the audit trail. The type=audit is required to refer to the audit trail. data classaudit; set mydata.class(type=audit); When we open the classaudit data set in viewtable we see that several records were created in the audit trail. Each record in the audit trail contains information about who modified the record, date & time, and type of modification. The modification type is stored in the _ATOPCODE_ variable with a code. The first record has a _ATOPCODE_ value of DR. The DR code means that this record is the record image before an update has occurred. The second record contains the _ATOPCODE_ value of DW. The DW means that this is the record after the update. This record also contains the _reason_change_ we set in the modify data step. The third record contains a _ATOPCODE_ value of DA. The DA code means that this record was added to the data set. The forth record has a _ATOPCODE_ value of DD. The DD code means that this record was deleted from the data set. Figure 2 shows what work.classaudit looks like.

Figure 2: Viewtable: Work.classaudit RECOVER RECORDS Normally, the only way to recover records that have been changed or deleted would be to restore a data set from backups or shadow copy. Backups may not be available if the error is detected weeks or months after the modification was made. With audit trails you can easily restore the original records back without having to contact your backup administrator. This is how it can be done. In the previous example we already modified John s age from 12 to 22. Now we can restore his original record back from the audit trail. We first create a transaction data set named rollbackupdate from the audit trail by running the code below. The rollbackupdate data set will contain the record image before it was updated. data rollbackupdate; set classaudit; where name = "John" and _ATOPCODE_ = "DR" and _ATUSERID_= "&sysuserid"; drop _: ;

Now we are ready to modify the master data set (mydata.class) with the transaction data set (rollbackupdate) we just created. We run the code below to modify the master data set with transaction data set. modify mydata.class rollbackupdate; by name; We now can open mydata.class with viewtable and see that John s age has been modified back to 12. Figure 3 shows the viewtable of mydata.class. Figure 3: Viewtable mydata.class ERROR IN SAS PROGRAM A SAS program normally contains many data steps and procedures. It is common to submit a program several times before the program runs without errors. A syntax error in the program or a system error will cause some data steps to finish successfully while some will not. Going thru the logs and figuring

out which data steps need to resubmitted can be a tedious and a time consuming task. An alternative is to use an audit trail and rollback records if an error occurs in the SAS program. We first create the macro rollbackerror to restore records during an error. The datasetname parameter is the name of the data set we recovering records from. The rollbackerror macro will look for records that were updated, deleted and restore the records back to the data set. %macro rollbackerror(datasetname); data &datasetname.audit; set &datasetname(type=audit); data rollbackupdate; set &datasetname.audit; where _ATOPCODE_ ="DR" and _ATUSERID_= "&sysuserid" and datepart(_atdatetime_) = today(); drop _: ; data rollbackdelete; set &datasetname.audit; where _ATOPCODE_ ="DD" and _ATUSERID_= "&sysuserid" and datepart(_atdatetime_) = today(); drop _:; data rollbackinsert; set &datasetname.audit; where _ATOPCODE_ ="DA" and _ATUSERID_= "&sysuserid" and datepart(_atdatetime_) = today(); drop _:; data &datasetname; modify &datasetname rollbackupdate; by name; proc append base=&datasetname data=rollbackdelete force; data &datasetname; modify &datasetname rollbackinsert; by name; remove; %mend; We now create a SAS program to modify a SAS data set. We initiate the audit trail for mydata.class and make several modifications to the data set. We then intentionally cause an error by adding an extra s to mydata.class. This will set the automatic macro variable syserr greater than 0 and the macro rollbackerror will be invoked. The rollbackerror macro will recover the records before they were updated and restore the deleted records. It will also delete records that were added to the data set.

%macro dosomething; libname mydata "c:\era\"; set sashelp.class; proc datasets lib=mydata; audit class; initiate; user_var _reason_change_ $30; quit; modify mydata.class; where name = "John"; age = "22"; _reason_change_ = "correct John's age"; proc sql; insert into mydata.class set name = "Minh", sex = "M", Age = 30, Weight = 175, Height = 66, _reason_change_ = "Moved to school"; quit; modify mydata.class; where name = "William"; remove; modify mydata.classs; *THIS WILL CAUSE AN ERROR; where name = "Jeff"; remove; %if &syserr > 0 %then %do; %rollbackerror(mydata.class); %end; proc datasets lib=mydata; audit class; terminate; quit; %mend; %dosomething;

We can run proc compare to verify that sashelp.class and mydata.class have the same values. Figure 4 shows the output of the proc compare. proc compare base=sashelp.class compare =mydata.class; Figure 4: proc compare of sashelp.class and mydata.class CONS OF AUDIT TRAIL There are disadvantages with using audit trails. Audit trails can become large quickly because it contains all the data and modifications. This can affect the performance of the SAS system when you are working with the data set. The audit trail also only applies to data changes made using a modify statement in the data step, UPDATE, INSERT, and DELETE statements with PROC SQL, or PROC APPEND. The audit trail will be deleted if the data set is rebuilt using the DATA step or SQL procedure. CONCLUSION Audit trails are a great tool for tracking modifications to SAS data sets. Not only does it allow you monitor changes but it also allows you to rollback to a previous version. I would encourage everyone to use audit trails in their environment.

REFERENCES (1) SAS 9.2 Language Reference Concepts http://support.sas.com/documentation/cdl/en/lrcon/61722/pdf/default/lrcon.pdf (2) Maria Y. Reis, Audit Trails of SAS Data Set Changes An Overview http://www.nesug.org/proceedings/nesug03/ph/ph006.pdf CONTACT INFORMATION Minh Duong minh.duong@times.uh.edu