@sasjs/core 4.62.0 → 4.63.0
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/mf_getvalue.sas +27 -8
- package/base/mp_validatecol.sas +15 -1
- package/package.json +1 -1
package/base/mf_getvalue.sas
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@file
|
|
3
|
-
@brief Retrieves a value from a dataset.
|
|
4
|
-
|
|
3
|
+
@brief Retrieves a value from a dataset. Returned value is fetched from the
|
|
4
|
+
'fetchobs=' record (row 1 by default), after applying the optional filter.
|
|
5
|
+
|
|
5
6
|
@details Be sure to <code>%quote()</code> your where clause. Example usage:
|
|
6
7
|
|
|
7
8
|
%put %mf_getvalue(sashelp.class,name,filter=%quote(age=15));
|
|
@@ -16,21 +17,39 @@
|
|
|
16
17
|
@param [in] libds dataset to query
|
|
17
18
|
@param [in] variable the variable which contains the value to return.
|
|
18
19
|
@param [in] filter= (1) contents of where clause
|
|
20
|
+
@param [in] fetchobs= (1) observation to fetch. NB: Filter applies first.
|
|
19
21
|
|
|
20
22
|
@version 9.2
|
|
21
23
|
@author Allan Bowe
|
|
22
24
|
**/
|
|
23
25
|
|
|
24
|
-
%macro mf_getvalue(libds,variable,filter=1
|
|
26
|
+
%macro mf_getvalue(libds,variable,filter=1,fetchobs=1
|
|
25
27
|
)/*/STORE SOURCE*/;
|
|
26
|
-
%
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
%local dsid;
|
|
29
|
+
|
|
30
|
+
%let dsid=%sysfunc(open(&libds(where=(&filter))));
|
|
31
|
+
%if (&dsid) %then %do;
|
|
32
|
+
%local rc &variable;
|
|
29
33
|
%syscall set(dsid);
|
|
30
|
-
%let rc = %sysfunc(
|
|
34
|
+
%let rc = %sysfunc(fetchobs(&dsid,&fetchobs));
|
|
35
|
+
%if (&rc ne 0) %then %do;
|
|
36
|
+
%put NOTE: Problem reading obs &fetchobs from &libds..;
|
|
37
|
+
%put %sysfunc(sysmsg());
|
|
38
|
+
/* Coerce an rc value of -1 (read past end of data) to a 4
|
|
39
|
+
that, in SAS condition code terms, represents the sysmsg
|
|
40
|
+
w@rning it generates. */
|
|
41
|
+
%if &rc eq -1 %then %let rc = 4;
|
|
42
|
+
/* And update SYSCC if the &rc value is higher */
|
|
43
|
+
%let syscc = %sysfunc(max(&syscc,&rc));
|
|
44
|
+
%end;
|
|
31
45
|
%let rc = %sysfunc(close(&dsid));
|
|
32
46
|
|
|
33
47
|
%trim(&&&variable)
|
|
34
48
|
|
|
35
49
|
%end;
|
|
36
|
-
%
|
|
50
|
+
%else %do;
|
|
51
|
+
%put %sysfunc(sysmsg());
|
|
52
|
+
%let syscc = %sysfunc(max(&syscc,%sysfunc(sysrc())));
|
|
53
|
+
%end;
|
|
54
|
+
|
|
55
|
+
%mend mf_getvalue;
|
package/base/mp_validatecol.sas
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@file
|
|
3
|
-
@brief Used to validate
|
|
3
|
+
@brief Used to validate values in a data step
|
|
4
4
|
@details Useful when sanitising inputs, to ensure that they arrive with a
|
|
5
5
|
certain pattern.
|
|
6
6
|
Usage:
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
@param [in] incol The column to be validated
|
|
28
28
|
@param [in] rule The rule to apply. Current rules:
|
|
29
29
|
@li ISINT - checks if the variable is an integer
|
|
30
|
+
@li ISLIB - checks if the value is a valid libref (NOT whether it exists)
|
|
30
31
|
@li ISNUM - checks if the variable is numeric
|
|
31
32
|
@li LIBDS - matches LIBREF.DATASET format
|
|
32
33
|
@li FORMAT - checks if the provided format is syntactically valid
|
|
@@ -65,6 +66,19 @@
|
|
|
65
66
|
else &outcol=1;
|
|
66
67
|
drop &tempcol;
|
|
67
68
|
%end;
|
|
69
|
+
%else %if &rule=ISLIB %then %do;
|
|
70
|
+
if _n_=1 then do;
|
|
71
|
+
retain &tempcol;
|
|
72
|
+
&tempcol=prxparse('/^[_a-z]\w{0,7}$/i');
|
|
73
|
+
if missing(&tempcol) then do;
|
|
74
|
+
putlog 'ERR' +(-1) "OR: Invalid expression for ISLIB";
|
|
75
|
+
stop;
|
|
76
|
+
end;
|
|
77
|
+
drop &tempcol;
|
|
78
|
+
end;
|
|
79
|
+
if prxmatch(&tempcol, trim(&incol)) then &outcol=1;
|
|
80
|
+
else &outcol=0;
|
|
81
|
+
%end;
|
|
68
82
|
%else %if &rule=LIBDS %then %do;
|
|
69
83
|
/* match libref.dataset */
|
|
70
84
|
if _n_=1 then do;
|
package/package.json
CHANGED