@sasjs/core 5.3.1 → 5.4.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 +18 -10
- package/base/mp_filtercheck.sas +47 -28
- package/package.json +1 -1
package/base/mf_getvalue.sas
CHANGED
|
@@ -29,26 +29,26 @@
|
|
|
29
29
|
|
|
30
30
|
%macro mf_getvalue(libds,variable,filter=1,fetchobs=1,warn=0
|
|
31
31
|
)/*/STORE SOURCE*/;
|
|
32
|
-
%local dsid rc vartype;
|
|
32
|
+
%local dsid rc vartype result;
|
|
33
33
|
|
|
34
34
|
%let vartype = %mf_getvartype(&libds,&variable);
|
|
35
35
|
|
|
36
36
|
%let dsid=%sysfunc(open(&libds(where=(&filter))));
|
|
37
37
|
%if (&dsid) %then %do;
|
|
38
|
-
%syscall set(dsid);
|
|
39
38
|
%let rc = %sysfunc(fetchobs(&dsid,&fetchobs));
|
|
40
39
|
%if (&rc ne 0) %then %do;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/*
|
|
44
|
-
%if (&vartype eq N) %then %let
|
|
40
|
+
/* Fetchobs() failed - Log any issue that was not 'read past end' */
|
|
41
|
+
%if (&rc ne -1) %then %put %sysfunc(sysmsg());
|
|
42
|
+
/* Set the result to a missing value dependent on type. */
|
|
43
|
+
%if (&vartype eq N) %then %let result = .;
|
|
44
|
+
%else %let result = ;
|
|
45
|
+
|
|
45
46
|
%if (&warn) %then %do;
|
|
46
47
|
%if (&rc eq -1) %then %do; /* read past end of data */
|
|
47
48
|
%put %sysfunc(
|
|
48
49
|
compbl(
|
|
49
|
-
%quote(WARN%str(ING): Missing value returned
|
|
50
|
-
%quote(
|
|
51
|
-
%quote(and/or fetchobs (&fetchobs).)
|
|
50
|
+
%quote(WARN%str(ING): Missing value returned for variable)
|
|
51
|
+
%quote(&variable after reading past end of &libds..)
|
|
52
52
|
)
|
|
53
53
|
);
|
|
54
54
|
%let rc=4;
|
|
@@ -57,9 +57,17 @@
|
|
|
57
57
|
/* And update SYSCC if the &rc value is higher */
|
|
58
58
|
%let syscc = %sysfunc(max(&syscc,&rc));
|
|
59
59
|
%end;
|
|
60
|
+
%else %do;
|
|
61
|
+
%let result = %sysfunc(
|
|
62
|
+
getvar&vartype(
|
|
63
|
+
&dsid
|
|
64
|
+
,%sysfunc(varnum(&dsid,&variable))
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
%end;
|
|
60
68
|
%let rc = %sysfunc(close(&dsid));
|
|
61
69
|
|
|
62
|
-
%trim(
|
|
70
|
+
%trim(&result)
|
|
63
71
|
|
|
64
72
|
%end;
|
|
65
73
|
%else %do;
|
package/base/mp_filtercheck.sas
CHANGED
|
@@ -29,7 +29,9 @@
|
|
|
29
29
|
@li SUBGROUP_ID - only integers
|
|
30
30
|
@li VARIABLE_NM - must be in the target table
|
|
31
31
|
@li OPERATOR_NM - only =/>/</<=/>=/BETWEEN/IN/NOT IN/NE/CONTAINS
|
|
32
|
-
@li RAW_VALUE - no unquoted values except integers, commas and spaces.
|
|
32
|
+
@li RAW_VALUE - no unquoted values except integers, commas and spaces. For
|
|
33
|
+
numeric columns, SAS date, datetime and time literals are also accepted, eg
|
|
34
|
+
'20APR2042'd, '01JAN1960:00:00:42'dt, '00:00:42't.
|
|
33
35
|
|
|
34
36
|
@returns The &outds table containing any bad rows, plus a REASON_CD column.
|
|
35
37
|
|
|
@@ -59,7 +61,7 @@
|
|
|
59
61
|
@version 9.3
|
|
60
62
|
@author Allan Bowe
|
|
61
63
|
|
|
62
|
-
@todo Support
|
|
64
|
+
@todo Support hex / name literals and exponents in RAW_VALUE field
|
|
63
65
|
**/
|
|
64
66
|
|
|
65
67
|
%macro mp_filtercheck(inds,targetds=,outds=work.badrecords,abort=YES);
|
|
@@ -93,8 +95,11 @@ data &outds;
|
|
|
93
95
|
/*length GROUP_LOGIC SUBGROUP_LOGIC $3 SUBGROUP_ID 8 VARIABLE_NM $32
|
|
94
96
|
OPERATOR_NM $10 RAW_VALUE $4000;*/
|
|
95
97
|
set &inds end=last;
|
|
96
|
-
length reason_cd $4032 vtype vtype2 $1 vnum dsid 8 tmp $4000;
|
|
97
|
-
drop tmp;
|
|
98
|
+
length reason_cd $4032 vtype vtype2 $1 vnum dsid 8 tmp $4000 re_temporal 8;
|
|
99
|
+
drop tmp re_temporal;
|
|
100
|
+
retain re_temporal;
|
|
101
|
+
/* SAS temporal literals - date, datetime and time */
|
|
102
|
+
if _n_=1 then re_temporal=prxparse("/^'[^']*'(dt|d|t)$/i");
|
|
98
103
|
|
|
99
104
|
/* quick check to ensure column exists */
|
|
100
105
|
if upcase(VARIABLE_NM) not in
|
|
@@ -203,6 +208,9 @@ data &outds;
|
|
|
203
208
|
end;
|
|
204
209
|
end;
|
|
205
210
|
|
|
211
|
+
/* a SAS temporal literal is a valid value for a numeric column */
|
|
212
|
+
if vtype='N' and prxmatch(re_temporal,cats(raw_value))>0 then return;
|
|
213
|
+
|
|
206
214
|
/* special logic */
|
|
207
215
|
if OPERATOR_NM in ('IN','NOT IN','BETWEEN') then do;
|
|
208
216
|
if OPERATOR_NM='BETWEEN' then raw_value1=tranwrd(raw_value,' AND ',',');
|
|
@@ -222,40 +230,51 @@ data &outds;
|
|
|
222
230
|
if vtype='N' then do i=1 to countc(raw_value1, ',')+1;
|
|
223
231
|
tmp=scan(raw_value1,i,',');
|
|
224
232
|
if cats(tmp) ne '.' and input(tmp, ?? 8.) eq . then do;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
'
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
/*
|
|
239
|
-
|
|
233
|
+
/* a SAS temporal literal is a valid value for a numeric column */
|
|
234
|
+
if prxmatch(re_temporal,cats(tmp))=0 then do;
|
|
235
|
+
if OPERATOR_NM ='BETWEEN' and subpad(upcase(tmp),1,1) in (
|
|
236
|
+
'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
|
|
237
|
+
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
|
|
238
|
+
)
|
|
239
|
+
then do;
|
|
240
|
+
/* check if the raw_value contains a valid variable NAME */
|
|
241
|
+
/* is not valid syntax for IN or NOT IN */
|
|
242
|
+
vnum=varnum(dsid,subpad(tmp,1,32));
|
|
243
|
+
if vnum>0 then do;
|
|
244
|
+
/* now we can get the type */
|
|
245
|
+
vtype2=vartype(dsid,vnum);
|
|
246
|
+
/* check type matches */
|
|
247
|
+
if vtype2 ne vtype then do;
|
|
248
|
+
REASON_CD=cats("Compared Type (",vtype2,") is not (",vtype,")");
|
|
249
|
+
putlog REASON_CD= dsid=;
|
|
250
|
+
call symputx('reason_cd',reason_cd,'l');
|
|
251
|
+
call symputx('nobs',_n_,'l');
|
|
252
|
+
output;
|
|
253
|
+
goto endstep;
|
|
254
|
+
end;
|
|
240
255
|
end;
|
|
241
256
|
else do;
|
|
242
|
-
REASON_CD=
|
|
243
|
-
putlog REASON_CD=
|
|
257
|
+
REASON_CD='Non Numeric value provided';
|
|
258
|
+
putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
|
|
244
259
|
call symputx('reason_cd',reason_cd,'l');
|
|
245
260
|
call symputx('nobs',_n_,'l');
|
|
246
261
|
output;
|
|
247
|
-
goto endstep;
|
|
248
262
|
end;
|
|
249
263
|
end;
|
|
264
|
+
else do;
|
|
265
|
+
REASON_CD='Non Numeric value provided';
|
|
266
|
+
putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
|
|
267
|
+
call symputx('reason_cd',reason_cd,'l');
|
|
268
|
+
call symputx('nobs',_n_,'l');
|
|
269
|
+
output;
|
|
270
|
+
end;
|
|
250
271
|
end;
|
|
251
|
-
REASON_CD='Non Numeric value provided';
|
|
252
|
-
putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
|
|
253
|
-
call symputx('reason_cd',reason_cd,'l');
|
|
254
|
-
call symputx('nobs',_n_,'l');
|
|
255
|
-
output;
|
|
256
272
|
end;
|
|
257
|
-
return;
|
|
258
273
|
end;
|
|
274
|
+
/* every value of a numeric IN / BETWEEN list is checked one by one above,
|
|
275
|
+
so a numeric list skips the generic check below - that would only flag
|
|
276
|
+
the list syntax itself. A character list is unchanged. */
|
|
277
|
+
if vtype='N' then return;
|
|
259
278
|
end;
|
|
260
279
|
else raw_value1=raw_value;
|
|
261
280
|
|
package/package.json
CHANGED