DATASETS Procedure

Example 11: Initiating an Audit File

Features:
AUDIT Statements and Options:
AUDIT
INITIATE
USER_VAR
LOG
SUSPEND
RESUME
TERMINATE

Program

libname mylib "c:\mylib";

data mylib.inventory;
input vendor $10. +1 item $4. +1 description $11. +1 units 4.;
datalines;
SmithFarms F001 Apples      10
Tropicana  B002 OrangeJuice 45
UpperCrust C215 WheatBread  25
;
run;

proc datasets lib=mylib;                                       
   audit inventory;
   initiate;
   user_var reason $ 30;
quit;

proc sql;      
   Insert into mylib.inventory values ('Bordens','B132', 'Milk', 100,
                                       'increase on hand'); 
   Update mylib.inventory    set units=10, reason='recounted inventory' 
                             where item='B002';  
quit;

proc datasets lib=mylib;   
audit inventory;
log admin_image=no;
suspend;
quit; 

proc sql;
select * from mylib.inventory(type=audit); 
quit; 

proc datasets lib=mylib;   /* resume audit file */
audit inventory;
resume;
quit;

/* additional step(s) which update the inventory dataset could go here*/

proc datasets lib=mylib;  /* terminate audit file */
audit inventory;
terminate;
quit;

Initiates an audit file using USER_VAR.
libname mylib "c:\mylib";

data mylib.inventory;
input vendor $10. +1 item $4. +1 description $11. +1 units 4.;
datalines;
SmithFarms F001 Apples      10
Tropicana  B002 OrangeJuice 45
UpperCrust C215 WheatBread  25
;
run;

proc datasets lib=mylib;                                       
   audit inventory;
   initiate;
   user_var reason $ 30;
quit;
Update the data set.
proc sql;      
   Insert into mylib.inventory values ('Bordens','B132', 'Milk', 100,
                                       'increase on hand'); 
   Update mylib.inventory    set units=10, reason='recounted inventory' 
                             where item='B002';  
quit;

Discontinue the logging of ADMIN images and suspend audit file.
proc datasets lib=mylib;   
audit inventory;
log admin_image=no;
suspend;
quit; 

View the audit file.
proc sql;
select * from mylib.inventory(type=audit); 
quit; 

Resume the audit file.
proc datasets lib=mylib; 
audit inventory;
resume;
quit;

Terminate the audit file.
proc datasets lib=mylib;  
audit inventory;
terminate;
quit;
1    options nocenter;
2
3    libname mylib "c:\mylib";
NOTE: Libref MYLIB was successfully assigned as follows:
      Engine:        V9
      Physical Name: c:\mylib
4
5    data mylib.inventory;
6    input vendor $10. +1 item $4. +1 description $11. +1 units 4.;
7    datalines;

NOTE: The data set MYLIB.INVENTORY has 3 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           3.45 seconds
      cpu time            0.00 seconds


11   ;
12   run;
13
14   proc datasets lib=mylib;
NOTE: Writing HTML Body file: sashtml.htm
15      audit inventory;
16      initiate;
WARNING: The audited data file MYLIB.INVENTORY.DATA is not password protected.  Apply an ALTER password to prevent accidental
         deletion or replacement of it and any associated audit files.
17      user_var reason $ 30;
18   quit;

NOTE: The data set MYLIB.INVENTORY.AUDIT has 0 observations and 11 variables.
NOTE: PROCEDURE DATASETS used (Total process time):
      real time           18.17 seconds
      cpu time            0.79 seconds


19
20   proc sql;
21      Insert into mylib.inventory values ('Bordens','B132', 'Milk', 100,
22                                          'increase on hand');
NOTE: 1 row was inserted into MYLIB.INVENTORY.

23      Update mylib.inventory    set units=10, reason='recounted inventory'
24                                where item='B002';
NOTE: 1 row was updated in MYLIB.INVENTORY.

25   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           2.57 seconds
      cpu time            0.03 seconds


26
27   proc datasets lib=mylib;
28   audit inventory;
29   log admin_image=no;
30   suspend;
31   quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


32
33   proc sql;
34   select * from mylib.inventory(type=audit);
35   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.54 seconds
      cpu time            0.01 seconds


36
37   proc datasets lib=mylib;
37 !                            /* resume audit file */
38   audit inventory;
39   resume;
40   quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


41
42   /* additional step(s) which update the inventory dataset could go here*/
43
44   proc datasets lib=mylib;
44 !                           /* terminate audit file */
45   audit inventory;
46   terminate;
NOTE: Deleting MYLIB.INVENTORY (memtype=AUDIT).
47   quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
program output
MYLIB Output 2
MYLIB Output 3
MYLIB Output 4
MYLIB Output 5