sas file functions can help you leave an audit trail

15
Subhash Mantha SAS Developer [email protected]

Upload: conor

Post on 17-Jan-2016

39 views

Category:

Documents


0 download

DESCRIPTION

SAS File functions can help you leave an audit trail. Subhash Mantha SAS Developer [email protected]. Audit trail. Important in the following fields Clinical Trials Financial Companies Product Development Answers four important questions When Why How Who. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SAS File functions can help you leave an audit trail

Subhash ManthaSAS Developer

[email protected]

Page 2: SAS File functions can help you leave an audit trail

Audit trailImportant in the following fields

Clinical TrialsFinancial CompaniesProduct Development

Answers four important questionsWhenWhyHowWho

Page 3: SAS File functions can help you leave an audit trail

Some of the parameters used for Trail CapturingDate TimeWho ran the programRun time of the program

Page 4: SAS File functions can help you leave an audit trail

Methods for capturing a trailSAS LogsExcel FilesXML filesSAS DatasetsCSV/Text Files

Page 5: SAS File functions can help you leave an audit trail

SAS Way of capturing a trailDatasets

AppendModifyRecreate

External filesAppendRecreate

Page 6: SAS File functions can help you leave an audit trail

Trail by datasetsData step

Set Modify

Proc stepAppend

Page 7: SAS File functions can help you leave an audit trail

Trail by external filesData step

File (recreate)File with mod option (append)

Proc stepProc export (Recreate /add new sheets to an

existing file)ODS CSVALL

Page 8: SAS File functions can help you leave an audit trail

Writing to external filesData stepProc stepSAS File functions

Page 9: SAS File functions can help you leave an audit trail

SAS File functionsFilename: Assigns a file reference in a data step Fexist: Checks if a file exists.Fopen : opens the file and creates a file handlerFclose : Closes the file that has been opened

using the file handlerFput : Writes the information to the file data

bufferFwrite : Writes data from file data buffer to the

actual file

Page 10: SAS File functions can help you leave an audit trail

Appending information to the bottom of a fileData step:Data _null_;File <fileref> <file options> mod;Set somedsname;Put fields we want;Run;File functions:Data _null_;Rc_open=filename(‘fileref’, “full file name along with path”);if rc_open=0 and fexist(‘fileref’) then do; fid=fopen(‘fileref’ , ’a’); putrc=fput(fid,<string to be written to the file>); writerc=fwrite(fid); closerc=fclose(fid);End;Run;

Page 11: SAS File functions can help you leave an audit trail

Advantages of using file functionsVerify if the file existsCheck if the file is in useWait until the file is available to useCatch exceptions if data write to a file failedHelp work around user locks

Page 12: SAS File functions can help you leave an audit trail

Concurrent access of datasetsFound in multi user systemsSeveral people trying to access the same fileOthers might have a file in read mode while

somebody else is trying to update the file

Methods to address concurrent access :“Assume” That it never happens as in a single

user systemTry to resolve the lock

Page 13: SAS File functions can help you leave an audit trail

Code%macro update_audit_file (name_of_program=, campaign_channel=,

result_of_run=&syscc._&sysrc._&sysmsg, name_of_audit_file=);

%local user date_of_run ; %let user=%sysget(USERNAME); %let date_of_run=%sysfunc(putn(%sysfunc(datetime()),datetime18.)); %let filerf=update;

proc sql noprint; select distinct scan(xpath,-1,'\') into :files separated by '|' from sashelp.vextfl where index(xpath,'.sas')>0; quit; %let rc=%sysfunc(filename(filerf,"&name_of_audit_file"));

%put rc=&rc; %if %sysfunc(fexist(&filerf)) %then %do;

%let open_rc=%sysfunc(fopen(&filerf,a)); %put &open_rc=; %do %while (&open_rc <= 0 ); %let rc_sleep=%sysfunc(sleep(10));

%put The file being updated is open please close it; %put SAS will try to update it in 10 seconds;

%let open_rc=%sysfunc(fopen(&filerf,a)); %end;

Page 14: SAS File functions can help you leave an audit trail

%if &open_rc > 0 %then %do; %let log=%sysfunc(getoption(altlog)); %let log_file=%sysfunc(scan(%str(&log),-1,'\'));

%let list=%sysfunc(getoption(altprint)); %let list_file=%sysfunc(scan(%str(&list),-1,'\')); %let path=%sysfunc(getoption(sasinitialfolder)); %let put_rc=%sysfunc(fput(&open_rc,

%str(&user,&date_of_run,&name_of_campaign,&campaign_channel,&path,&result_of_run,&log_file,&list_file,&files)));

%let write_rc=%sysfunc(fwrite(&open_rc)); %let close_rc=%sysfunc(fclose(&open_rc)); %end; %put &open_rc &close_rc;

%end; %else %do; %put the file &filerf does not exist;

%put creating file &name_of_audit_file; data _null_; file "&name_of_audit_file"; put 'user,dateofrun,name_of_campaign,campaign_channel,path,result_of_run,log_file,list_file,files'; %put %sysfunc(sysmsg());

%end; %mend update_audit_file;

Code Continued….

Page 15: SAS File functions can help you leave an audit trail

ReferencesSAS on-line documentation in Release 9.1.3Using SAS Functions in Data Steps, Yue Ye, The

R.W. Johnson Pharmaceutical Research Institute, Raritan, NJ Yong Lin, The Cancer Institute of New Jersey, New Brunswick, NJ

AcknowledgementsVitaly Feldman, SAS Institute Inc.