mp_lockfilecheck.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Aborts if a SAS lock file is in place, or if one cannot be applied.
4  @details Used in conjuction with the mp_lockanytable macro.
5  More info here: https://sasensei.com/flash/24
6 
7  Usage:
8 
9  data work.test; a=1;run;
10  %mp_lockfilecheck(work.test)
11 
12  @param [in] libds The libref.dataset for which to check the lock status
13 
14  <h4> SAS Macros </h4>
15  @li mp_abort.sas
16  @li mf_getattrc.sas
17 
18  <h4> Related Macros </h4>
19  @li mp_lockanytable.sas
20  @li mp_lockfilecheck.test.sas
21 
22  @version 9.2
23 **/
24 
25 %macro mp_lockfilecheck(
26  libds
27 )/*/STORE SOURCE*/;
28 
29 data _null_;
30  if _n_=1 then putlog "&sysmacroname entry vars:";
31  set sashelp.vmacro;
32  where scope="&sysmacroname";
33  put name '=' value;
34 run;
35 
36 %mp_abort(iftrue= (&syscc>0)
37  ,mac=checklock.sas
38  ,msg=Aborting with syscc=&syscc on entry.
39 )
40 %mp_abort(iftrue= ("&libds"="0")
41  ,mac=&sysmacroname
42  ,msg=%str(libds not provided)
43 )
44 
45 %local msg lib ds;
46 %let lib=%upcase(%scan(&libds,1,.));
47 %let ds=%upcase(%scan(&libds,2,.));
48 
49 /* in DC, format catalogs are passed with a -FC suffix. No saslock here! */
50 %if %scan(&libds,2,-)=FC %then %do;
51  %put &sysmacroname: Format Catalog detected, no lockfile applied to &libds;
52  %return;
53 %end;
54 
55 /* do not proceed if no observations can be processed */
56 %let msg=options obs = 0. syserrortext=%superq(syserrortext);
57 %mp_abort(iftrue= (%sysfunc(getoption(OBS))=0)
58  ,mac=checklock.sas
59  ,msg=%superq(msg)
60 )
61 
62 data _null_;
63  putlog "Checking engine & member type";
64 run;
65 %local engine memtype;
66 %let memtype=%mf_getattrc(&libds,MTYPE);
67 %let engine=%mf_getattrc(&libds,ENGINE);
68 
69 %if &engine ne V9 and &engine ne BASE %then %do;
70  data _null_;
71  putlog "Lib &lib is not assigned using BASE engine - uses &engine instead";
72  putlog "SAS lock check will not be performed";
73  run;
74  %return;
75 %end;
76 %else %if &memtype ne DATA %then %do;
77  %put NOTE: Cannot lock a VIEW!! Memtype=&memtype;
78  %return;
79 %end;
80 
81 data _null_;
82  putlog "Engine = &engine, memtype=&memtype";
83  putlog "Attempting lock statement";
84 run;
85 
86 lock &libds;
87 
88 %local abortme;
89 %let abortme=0;
90 %if &syscc>0 or &SYSLCKRC ne 0 %then %do;
91  %let msg=Unable to apply lock on &libds (SYSLCKRC=&SYSLCKRC syscc=&syscc);
92  %put %str(ERR)OR: &sysmacroname: &msg;
93  %let abortme=1;
94 %end;
95 
96 lock &libds clear;
97 
98 %mp_abort(iftrue= (&abortme=1)
99  ,mac=&sysmacroname
100  ,msg=%superq(msg)
101 )
102 
103 %mend mp_lockfilecheck;