@sasjs/core 2.56.2 → 2.56.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base/mp_searchdata.sas +37 -26
- package/package.json +1 -1
package/base/mp_searchdata.sas
CHANGED
|
@@ -11,22 +11,28 @@
|
|
|
11
11
|
Usage:
|
|
12
12
|
|
|
13
13
|
%mp_searchdata(lib=sashelp, string=Jan)
|
|
14
|
-
%mp_searchdata(lib=sashelp, numval=1)
|
|
14
|
+
%mp_searchdata(lib=sashelp, ds=bird, numval=1)
|
|
15
|
+
%mp_searchdata(lib=sashelp, ds=class, string=l,outobs=5)
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
Outputs zero or more tables to an MPSEARCH library with specific records.
|
|
18
19
|
|
|
19
|
-
@param lib=
|
|
20
|
-
@param ds=
|
|
21
|
-
@param string=
|
|
22
|
-
@param numval=
|
|
23
|
-
@param outloc= the directory in which to
|
|
24
|
-
matching rows.
|
|
25
|
-
|
|
20
|
+
@param [in] lib= The libref to search (should be already assigned)
|
|
21
|
+
@param [in] ds= The dataset to search (leave blank to search entire library)
|
|
22
|
+
@param [in] string= String value to search (case sensitive, can be partial)
|
|
23
|
+
@param [in] numval= Numeric value to search (must be exact)
|
|
24
|
+
@param [out] outloc= (0) Optionally specify the directory in which to
|
|
25
|
+
create the the output datasets with matching rows. By default it will
|
|
26
|
+
write them to a temporary subdirectory within the WORK folder.
|
|
27
|
+
@param [out] outlib= (MPSEARCH) Assign a different libref to the output
|
|
28
|
+
library containing the matching datasets / records
|
|
29
|
+
@param [in] outobs= set to a positive integer to restrict the number of
|
|
26
30
|
observations
|
|
27
|
-
@param filter_text=
|
|
31
|
+
@param [in] filter_text= (1=1) Add a (valid) filter clause to further filter
|
|
32
|
+
the results.
|
|
28
33
|
|
|
29
34
|
<h4> SAS Macros </h4>
|
|
35
|
+
@li mf_getuniquename.sas
|
|
30
36
|
@li mf_getvarlist.sas
|
|
31
37
|
@li mf_getvartype.sas
|
|
32
38
|
@li mf_mkdir.sas
|
|
@@ -36,11 +42,12 @@
|
|
|
36
42
|
@author Allan Bowe
|
|
37
43
|
**/
|
|
38
44
|
|
|
39
|
-
%macro mp_searchdata(lib=
|
|
45
|
+
%macro mp_searchdata(lib=
|
|
40
46
|
,ds=
|
|
41
47
|
,string= /* the query will use a contains (?) operator */
|
|
42
48
|
,numval= /* numeric must match exactly */
|
|
43
|
-
,outloc
|
|
49
|
+
,outloc=0
|
|
50
|
+
,outlib=MPSEARCH
|
|
44
51
|
,outobs=-1
|
|
45
52
|
,filter_text=%str(1=1)
|
|
46
53
|
)/*/STORE SOURCE*/;
|
|
@@ -57,8 +64,12 @@
|
|
|
57
64
|
%if &string = %then %let type=N;
|
|
58
65
|
%else %let type=C;
|
|
59
66
|
|
|
67
|
+
%if "&outloc"="0" %then %do;
|
|
68
|
+
%let outloc=%sysfunc(pathname(work))/%mf_getuniquename();
|
|
69
|
+
%end;
|
|
70
|
+
|
|
60
71
|
%mf_mkdir(&outloc)
|
|
61
|
-
libname
|
|
72
|
+
libname &outlib "&outloc";
|
|
62
73
|
|
|
63
74
|
/* get the list of tables in the library */
|
|
64
75
|
proc sql noprint;
|
|
@@ -70,11 +81,6 @@ select distinct memname into: table_list separated by ' '
|
|
|
70
81
|
%end;
|
|
71
82
|
;
|
|
72
83
|
/* check that we have something to check */
|
|
73
|
-
proc sql
|
|
74
|
-
%if &outobs>-1 %then %do;
|
|
75
|
-
outobs=&outobs
|
|
76
|
-
%end;
|
|
77
|
-
;
|
|
78
84
|
%if %length(&table_list)=0 %then %put library &lib contains no tables!;
|
|
79
85
|
/* loop through each table */
|
|
80
86
|
%else %do table_num=1 %to %sysfunc(countw(&table_list,%str( )));
|
|
@@ -85,10 +91,10 @@ proc sql
|
|
|
85
91
|
%end;
|
|
86
92
|
%else %do;
|
|
87
93
|
%let check_tm=%sysfunc(datetime());
|
|
88
|
-
/*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
/* prep input */
|
|
95
|
+
data &outlib..&table;
|
|
96
|
+
set &lib..&table;
|
|
97
|
+
where %unquote(&filter_text) and ( 0
|
|
92
98
|
/* loop through columns */
|
|
93
99
|
%do colnum=1 %to %sysfunc(countw(&vars,%str( )));
|
|
94
100
|
%let col=%scan(&vars,&colnum,%str( ));
|
|
@@ -102,15 +108,20 @@ proc sql
|
|
|
102
108
|
or ("&col"n = &numval)
|
|
103
109
|
%end;
|
|
104
110
|
%end;
|
|
105
|
-
|
|
111
|
+
);
|
|
112
|
+
%if &outobs>-1 %then %do;
|
|
113
|
+
if _n_ > &outobs then stop;
|
|
114
|
+
%end;
|
|
115
|
+
run;
|
|
106
116
|
%put Search query for &table took
|
|
107
117
|
%sysevalf(%sysfunc(datetime())-&check_tm) seconds;
|
|
108
|
-
%if &
|
|
109
|
-
%put %str(
|
|
118
|
+
%if &syscc ne 0 %then %do;
|
|
119
|
+
%put %str(ERR)ROR: SYSCC=&syscc when processing &lib..&table;
|
|
110
120
|
%return;
|
|
111
121
|
%end;
|
|
112
|
-
%if %mf_nobs(
|
|
113
|
-
|
|
122
|
+
%if %mf_nobs(&outlib..&table)=0 %then %do;
|
|
123
|
+
proc sql;
|
|
124
|
+
drop table &outlib..&table;
|
|
114
125
|
%end;
|
|
115
126
|
%end;
|
|
116
127
|
%end;
|
package/package.json
CHANGED