-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfindtable.sas
106 lines (81 loc) · 2.88 KB
/
findtable.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
%macro FindTable(lib,terms) / des="Find a table in a library";
/********************************************************************************
BEGIN MACRO HEADER
********************************************************************************
Name: FindTable
Author: Chris Swenson
Created: 2010-06-14
Purpose: Find a table in a library
Arguments: lib - library to search
terms - one or more terms to search for, separted by spaces
Revisions
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Date Author Comments
¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ ¯¯¯¯¯¯¯¯
YYYY-MM-DD III Please use this format and insert new entries above
********************************************************************************
END MACRO HEADER
********************************************************************************/
%let lib=%upcase(&lib);
%let terms=%upcase(&terms);
/* Check arguments */
%if "&lib"="" %then %do;
%put %str(E)RROR: Missing library argument.;
%return;
%end;
%if %sysfunc(libref(&lib)) ne 0 %then %do;
%put %str(W)ARNING: Specified library does not exist.;
%return;
%end;
%if "&terms"="" %then %do;
%put %str(E)RROR: Missing terms argument.;
%return;
%end;
/* Identify how many by variables are specified */
%local count next i msg;
%let count=1;
%let next=%scan(&terms, &count);
%do %until("&next"="");
%let count=%eval(&count+1);
%let next=%scan(&terms, &count);
%end;
%let count=%eval(&count-1);
%put NOTE: Number of by variables specified: &count;
/****************************************************************************/
/* Copy VTable */
proc sql;
create table _vtable_ as
select * from sashelp.vtable
where upcase(libname)="&LIB"
;
run;
%let user_mprint=%sysfunc(getoption(mprint));
option nomprint;
/* Set default message */
%let msg=%str(E)RROR- No matches found in &lib for &terms..;
/* Search for variable */
data _null_;
set _vtable_ end=end;
where
(
%do i=1 %to &count;
index(upcase(memname), "%scan(&terms, &i)")
%if &i ne &count %then %do;
or
%end;
%end;
)
;
if _n_=1 then put "NOTE: Possible matches:";
put "%str(W)ARNING- " memname;
if end then do;
put "NOTE-";
call symputx('msg', "%str(W)ARNING- Matches found in &lib for &terms.. See above.");
end;
run;
proc sql;
drop table _vtable_;
quit;
%put &msg;
option &user_mprint;
%mend FindTable;