@sasjs/core 5.3.2 → 5.5.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.
@@ -0,0 +1,65 @@
1
+ /**
2
+ @file
3
+ @brief Returns the SAS format names that carry a date, datetime or time value
4
+
5
+ @details Prints a quoted, comma separated list of format NAMES, for use in
6
+ open code or in generated code:
7
+
8
+ if upcase(fmt) in (%mf_dttmfmts(DATE)) then fmttype='DATE';
9
+ else if upcase(fmt) in (%mf_dttmfmts(DATETIME)) then fmttype='DATETIME';
10
+ else if upcase(fmt) in (%mf_dttmfmts(TIME)) then fmttype='TIME';
11
+ else fmttype='NUM';
12
+
13
+ The names carry no width or decimal suffix, so strip that first (eg DATE9.
14
+ becomes DATE). This macro is the single source of truth for the lists -
15
+ mcf_getfmttype.sas builds its FCMP lookups from it.
16
+
17
+ @param [in] type DATE / DATETIME / TIME (case insensitive)
18
+
19
+ <h4> SAS Macros </h4>
20
+ @li mp_abort.sas
21
+
22
+ <h4> Related Macros </h4>
23
+ @li mcf_getfmttype.sas
24
+
25
+ @version 9.4
26
+ @author Allan Bowe
27
+ **/
28
+
29
+ %macro mf_dttmfmts(type);
30
+ %local type found;
31
+ %let type=%upcase(&type);
32
+ %let found=0;
33
+ /* so an empty type reaches the abort below, rather than an %eval error */
34
+ %if %length(&type)=0 %then %let type=INVALID;
35
+
36
+ %if &type=DATE %then %do;
37
+ %let found=1;
38
+ 'DATE','YYMMDD','B8601DA','DAY','DDMMYY','DDMMYYB','DDMMYYC','DDMMYYD',
39
+ 'DDMMYYN','DDMMYYP','DDMMYYS','DDMMYYx','DOWNAME','E8601DA','JULDAY',
40
+ 'JULIAN','MMDDYY','MMDDYYB','MMDDYYC','MMDDYYD','MMDDYYN','MMDDYYP',
41
+ 'MMDDYYS','MMDDYYx','MMYY','MMYYC','MMYYD','MMYYN','MMYYP','MMYYS','MMYYx',
42
+ 'MONNAME','MONTH','MONYY','PDJULG','PDJULI','QTR','QTRR','WEEKDATE',
43
+ 'WEEKDATX','WEEKDAY','WEEKU','WEEKV','WEEKW','WORDDATE','WORDDATX','YEAR',
44
+ 'YYMM','YYMMC','YYMMD','YYMMDDB','YYMMDDC','YYMMDDD','YYMMDDN','YYMMDDP',
45
+ 'YYMMDDS','YYMMDDx','YYMMN','YYMMP','YYMMS','YYMMx','YYMON','YYQ','YYQC',
46
+ 'YYQD','YYQN','YYQP','YYQR','YYQRC','YYQRD','YYQRN','YYQRP','YYQRS',
47
+ 'YYQRx','YYQS','YYQx','YYQZ','NLDATE'
48
+ %end;
49
+ %else %if &type=DATETIME %then %do;
50
+ %let found=1;
51
+ 'DATETIME','B8601DN','B8601DT','B8601DZ','DATEAMPM','DTDATE','DTMONYY',
52
+ 'DTWKDATX','DTYEAR','DTYYQC','E8601DN','E8601DT','E8601DZ','NLDATM'
53
+ %end;
54
+ %else %if &type=TIME %then %do;
55
+ %let found=1;
56
+ 'TIME','B8601LZ','B8601TM','B8601TZ','E8601LZ','E8601TM','E8601TZ','HHMM',
57
+ 'HOUR','MMSS','TIMEAMPM','TOD'
58
+ %end;
59
+
60
+ %mp_abort(iftrue=(&found=0)
61
+ ,mac=&sysmacroname
62
+ ,msg=%str(type must be DATE, DATETIME or TIME - got: &type)
63
+ )
64
+
65
+ %mend mf_dttmfmts;
@@ -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 date / hex / name literals and exponents in RAW_VALUE field
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
- if OPERATOR_NM ='BETWEEN' and subpad(upcase(tmp),1,1) in (
226
- 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
227
- 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
228
- )
229
- then do;
230
- /* check if the raw_value contains a valid variable NAME */
231
- /* is not valid syntax for IN or NOT IN */
232
- vnum=varnum(dsid,subpad(tmp,1,32));
233
- if vnum>0 then do;
234
- /* now we can get the type */
235
- vtype2=vartype(dsid,vnum);
236
- /* check type matches */
237
- if vtype2=vtype then do;
238
- /* valid target var - exit loop */
239
- return;
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=cats("Compared Type (",vtype2,") is not (",vtype,")");
243
- putlog REASON_CD= dsid=;
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
 
@@ -3,7 +3,8 @@
3
3
  @brief Returns the type of the format
4
4
  @details
5
5
  Returns the type, eg DATE / DATETIME / TIME (based on hard-coded lookup)
6
- else CHAR / NUM.
6
+ else CHAR / NUM. The lookup lists live in mf_dttmfmts.sas, which is also
7
+ usable directly in open code.
7
8
 
8
9
  This macro may be extended in the future to support custom formats - this
9
10
  would necessitate a call to `dosubl()` for running a proc format with cntlout.
@@ -38,6 +39,7 @@
38
39
 
39
40
  <h4> SAS Macros </h4>
40
41
  @li mcf_init.sas
42
+ @li mf_dttmfmts.sas
41
43
 
42
44
  <h4> Related Programs </h4>
43
45
  @li mcf_getfmttype.test.sas
@@ -74,25 +76,10 @@ function mcf_getfmttype(fmtnm $) $8;
74
76
  else fmt=substr(fmt,1,length(fmt)-1);
75
77
  end;
76
78
 
77
- /* apply lookups */
78
- if cats(fmt) in ('DATETIME','B8601DN','B8601DN','B8601DT','B8601DT'
79
- ,'B8601DZ','B8601DZ','DATEAMPM','DTDATE','DTMONYY','DTWKDATX','DTYEAR'
80
- ,'DTYYQC','E8601DN','E8601DN','E8601DT','E8601DT','E8601DZ','E8601DZ'
81
- ,'NLDATM') then return('DATETIME');
82
- else if fmt in ('DATE','YYMMDD','B8601DA','B8601DA','DAY','DDMMYY'
83
- ,'DDMMYYB','DDMMYYC','DDMMYYD','DDMMYYN','DDMMYYP','DDMMYYS','DDMMYYx'
84
- ,'DOWNAME','E8601DA','E8601DA','JULDAY','JULIAN','MMDDYY','MMDDYYB'
85
- ,'MMDDYYC','MMDDYYD','MMDDYYN','MMDDYYP','MMDDYYS','MMDDYYx','MMYY'
86
- ,'MMYYC','MMYYD','MMYYN','MMYYP','MMYYS','MMYYx','MONNAME','MONTH'
87
- ,'MONYY','PDJULG','PDJULI','QTR','QTRR','WEEKDATE','WEEKDATX','WEEKDAY'
88
- ,'WEEKU','WEEKV','WEEKW','WORDDATE','WORDDATX','YEAR','YYMM','YYMMC'
89
- ,'YYMMD','YYMMDDB','YYMMDDC','YYMMDDD','YYMMDDN','YYMMDDP','YYMMDDS'
90
- ,'YYMMDDx','YYMMN','YYMMP','YYMMS','YYMMx','YYMON','YYQ','YYQC','YYQD'
91
- ,'YYQN','YYQP','YYQR','YYQRC','YYQRD','YYQRN','YYQRP','YYQRS','YYQRx'
92
- ,'YYQS','YYQx','YYQZ','NLDATE') then return('DATE');
93
- else if fmt in ('TIME','B8601LZ','B8601LZ','B8601TM','B8601TM','B8601TZ'
94
- ,'B8601TZ','E8601LZ','E8601LZ','E8601TM','E8601TM','E8601TZ','E8601TZ'
95
- ,'HHMM','HOUR','MMSS','TIMEAMPM','TOD') then return('TIME');
79
+ /* apply lookups - the format lists live in mf_dttmfmts.sas */
80
+ if cats(fmt) in (%mf_dttmfmts(DATETIME)) then return('DATETIME');
81
+ else if cats(fmt) in (%mf_dttmfmts(DATE)) then return('DATE');
82
+ else if cats(fmt) in (%mf_dttmfmts(TIME)) then return('TIME');
96
83
  else return('NUM');
97
84
  end;
98
85
  endsub;
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "devDependencies": {
44
44
  "@nogoo9/gitleaks": "8.30.1-post.2"
45
45
  },
46
- "version": "5.3.2"
46
+ "version": "5.5.0"
47
47
  }