-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdroptable.sas
75 lines (59 loc) · 2.32 KB
/
droptable.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
%macro DropTable(tables) / pbuff des='Drop table(s)';
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: DropTable
Author: Chris Swenson
Created: 2009-10-02
Purpose: Drop table(s) if they exist
Arguments: tables - one or more tables to drop
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
2011-08-24 CAS Removed LIBTBL macro in favor of in-macro code.
2011-12-28 CAS Updated to use USER library if available.
2019-12-14 CAS Added LIB m. var to LOCAL to avoid conflicts.
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
%if "&tables"="" or "&tables"="()" %then %do;
%put %str(E)RROR: No tables specified.;
%return;
%end;
%local num ds lib;
%let num=1;
%let ds=%scan(&tables, &num, %str( )());
%let lib=%scan(&ds, 1, %str(.));
%if &lib=&ds %then %do;;
%if %sysfunc(libref(user))=0 %then %let lib=user;
%else %let lib=work;
%end;
%if %sysfunc(libref(&lib)) ne 0 %then %do;
%put %str(E)RROR: The specified library does not exist.;
%return;
%end;
proc sql;
%do %while("&ds" ne "");
%if %sysfunc(exist(&ds)) %then %do;
drop table &ds;
%end;
%else %do;
%put NOTE: Table %upcase(&ds) does not exist.;
%end;
%next:
%let num=%eval(&num+1);
%let ds=%scan(&tables, &num, %str( )());
%let lib=%scan(&ds, 1, %str(.));
%if &lib=&ds %then %do;;
%if %sysfunc(libref(user))=0 %then %let lib=user;
%else %let lib=work;
%end;
%if %sysfunc(libref(&lib)) ne 0 %then %do;
%put %str(E)RROR: The specified library does not exist.;
%goto next;
%end;
%end;
quit;
%mend DropTable;