@sasjs/core 4.48.3 → 4.49.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/README.md CHANGED
@@ -248,7 +248,7 @@ The following repositories are also worth checking out:
248
248
 
249
249
  ## Contributors ✨
250
250
  <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
251
- [![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors-)
251
+ [![All Contributors](https://img.shields.io/badge/all_contributors-15-orange.svg?style=flat-square)](#contributors-)
252
252
  <!-- ALL-CONTRIBUTORS-BADGE:END -->
253
253
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
254
254
 
@@ -275,6 +275,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
275
275
  <td align="center" valign="top" width="14.28%"><a href="https://github.com/henrik-forsell"><img src="https://avatars.githubusercontent.com/u/109935936?v=4?s=100" width="100px;" alt="Henrik Forsell"/><br /><sub><b>Henrik Forsell</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=henrik-forsell" title="Documentation">📖</a></td>
276
276
  <td align="center" valign="top" width="14.28%"><a href="http://rudvfaden.github.io/"><img src="https://avatars.githubusercontent.com/u/2445577?v=4?s=100" width="100px;" alt="Rud Faden"/><br /><sub><b>Rud Faden</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=rudvfaden" title="Code">💻</a></td>
277
277
  </tr>
278
+ <tr>
279
+ <td align="center" valign="top" width="14.28%"><a href="https://github.com/andyjessen"><img src="https://avatars.githubusercontent.com/u/62343929?v=4?s=100" width="100px;" alt="andyjessen"/><br /><sub><b>andyjessen</b></sub></a><br /><a href="https://github.com/sasjs/core/commits?author=andyjessen" title="Documentation">📖</a></td>
280
+ </tr>
278
281
  </tbody>
279
282
  </table>
280
283
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  Usage:
9
9
 
10
- %put mf_isblank(&var);
10
+ %put %mf_isblank(&var);
11
11
 
12
12
  inspiration:
13
13
  https://support.sas.com/resources/papers/proceedings09/022-2009.pdf
@@ -79,8 +79,8 @@ data &cntlout/nonote2err;
79
79
  end;
80
80
 
81
81
  /* create row marker. Data cannot be sorted without it! */
82
- if first.fmtname then fmtrow=0;
83
- fmtrow+1;
82
+ if first.fmtname then fmtrow=1;
83
+ else fmtrow+1;
84
84
 
85
85
  run;
86
86
  proc sort;
@@ -86,15 +86,14 @@
86
86
  /**
87
87
  * Sanitise the values based on valid value lists, then strip out
88
88
  * quotes, commas, periods and spaces.
89
- * Only numeric values should remain
90
89
  */
91
90
  %local reason_cd nobs;
92
91
  %let nobs=0;
93
92
  data &outds;
94
93
  /*length GROUP_LOGIC SUBGROUP_LOGIC $3 SUBGROUP_ID 8 VARIABLE_NM $32
95
94
  OPERATOR_NM $10 RAW_VALUE $4000;*/
96
- set &inds;
97
- length reason_cd $4032 vtype $1 vnum dsid 8 tmp $4000;
95
+ set &inds end=last;
96
+ length reason_cd $4032 vtype vtype2 $1 vnum dsid 8 tmp $4000;
98
97
  drop tmp;
99
98
 
100
99
  /* quick check to ensure column exists */
@@ -110,7 +109,8 @@ data &outds;
110
109
  end;
111
110
 
112
111
  /* need to open the dataset to get the column type */
113
- dsid=open("&targetds","i");
112
+ retain dsid;
113
+ if _n_=1 then dsid=open("&targetds","i");
114
114
  if dsid>0 then do;
115
115
  vnum=varnum(dsid,VARIABLE_NM);
116
116
  if vnum<1 then do;
@@ -120,11 +120,19 @@ data &outds;
120
120
  call symputx('reason_cd',reason_cd,'l');
121
121
  call symputx('nobs',_n_,'l');
122
122
  output;
123
- return;
123
+ goto endstep;
124
124
  end;
125
125
  /* now we can get the type */
126
126
  else vtype=vartype(dsid,vnum);
127
127
  end;
128
+ else do;
129
+ REASON_CD=cats("Could not open &targetds");
130
+ putlog REASON_CD= dsid=;
131
+ call symputx('reason_cd',reason_cd,'l');
132
+ call symputx('nobs',_n_,'l');
133
+ output;
134
+ stop;
135
+ end;
128
136
 
129
137
  /* closed list checks */
130
138
  if GROUP_LOGIC not in ('AND','OR') then do;
@@ -159,15 +167,40 @@ data &outds;
159
167
  end;
160
168
 
161
169
  /* special missing logic */
162
- if vtype='N'
163
- and OPERATOR_NM in ('=','>','<','<=','>=','NE','GE','LE')
164
- and cats(upcase(raw_value)) in (
170
+ if vtype='N' & OPERATOR_NM in ('=','>','<','<=','>=','NE','GE','LE') then do;
171
+ if cats(upcase(raw_value)) in (
165
172
  '.','.A','.B','.C','.D','.E','.F','.G','.H','.I','.J','.K','.L','.M','.N'
166
173
  '.N','.O','.P','.Q','.R','.S','.T','.U','.V','.W','.X','.Y','.Z','._'
167
174
  )
168
- then do;
169
- /* valid numeric - exit data step loop */
170
- return;
175
+ then do;
176
+ /* valid numeric - exit data step loop */
177
+ return;
178
+ end;
179
+ else if subpad(upcase(raw_value),1,1) in (
180
+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
181
+ 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
182
+ )
183
+ then do;
184
+ /* check if the raw_value contains a valid variable NAME */
185
+ vnum=varnum(dsid,subpad(raw_value,1,32));
186
+ if vnum>0 then do;
187
+ /* now we can get the type */
188
+ vtype2=vartype(dsid,vnum);
189
+ /* check type matches */
190
+ if vtype2=vtype then do;
191
+ /* valid target var - exit loop */
192
+ return;
193
+ end;
194
+ else do;
195
+ REASON_CD=cats("Compared Type (",vtype2,") is not (",vtype,")");
196
+ putlog REASON_CD= dsid=;
197
+ call symputx('reason_cd',reason_cd,'l');
198
+ call symputx('nobs',_n_,'l');
199
+ output;
200
+ goto endstep;
201
+ end;
202
+ end;
203
+ end;
171
204
  end;
172
205
 
173
206
  /* special logic */
@@ -189,6 +222,32 @@ data &outds;
189
222
  if vtype='N' then do i=1 to countc(raw_value1, ',')+1;
190
223
  tmp=scan(raw_value1,i,',');
191
224
  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;
240
+ end;
241
+ else do;
242
+ REASON_CD=cats("Compared Type (",vtype2,") is not (",vtype,")");
243
+ putlog REASON_CD= dsid=;
244
+ call symputx('reason_cd',reason_cd,'l');
245
+ call symputx('nobs',_n_,'l');
246
+ output;
247
+ goto endstep;
248
+ end;
249
+ end;
250
+ end;
192
251
  REASON_CD='Non Numeric value provided';
193
252
  putlog REASON_CD= OPERATOR_NM= raw_value= raw_value1= ;
194
253
  call symputx('reason_cd',reason_cd,'l');
@@ -213,14 +272,42 @@ data &outds;
213
272
 
214
273
  /* output records that contain values other than digits and spaces */
215
274
  if notdigit(compress(raw_value3,' '))>0 then do;
275
+ if vtype='C' and subpad(upcase(raw_value),1,1) in (
276
+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N'
277
+ 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z','_'
278
+ )
279
+ then do;
280
+ /* check if the raw_value contains a valid variable NAME */
281
+ vnum=varnum(dsid,subpad(raw_value,1,32));
282
+ if vnum>0 then do;
283
+ /* now we can get the type */
284
+ vtype2=vartype(dsid,vnum);
285
+ /* check type matches */
286
+ if vtype2=vtype then do;
287
+ /* valid target var - exit loop */
288
+ return;
289
+ end;
290
+ else do;
291
+ REASON_CD=cats("Compared Char Type (",vtype2,") is not (",vtype,")");
292
+ putlog REASON_CD= dsid=;
293
+ call symputx('reason_cd',reason_cd,'l');
294
+ call symputx('nobs',_n_,'l');
295
+ output;
296
+ goto endstep;
297
+ end;
298
+ end;
299
+ end;
300
+
216
301
  putlog raw_value3= $hex32.;
217
302
  REASON_CD=cats('Invalid RAW_VALUE:',raw_value);
218
- putlog REASON_CD= raw_value= raw_value1= raw_value2= raw_value3=;
303
+ putlog (_all_)(=);
219
304
  call symputx('reason_cd',reason_cd,'l');
220
305
  call symputx('nobs',_n_,'l');
221
306
  output;
222
307
  end;
223
308
 
309
+ endstep:
310
+ if last then rc=close(dsid);
224
311
  run;
225
312
 
226
313
 
@@ -9,6 +9,9 @@
9
9
  format, to prevent loss of data - UNLESS the input dataset contains a marker
10
10
  column, specifying that a particular row needs to be deleted (`delete_col=`).
11
11
 
12
+ Positions of formats are made using the FMTROW variable - this must be present
13
+ and unique (on TYPE / FMTNAME / FMTROW).
14
+
12
15
  This macro can also be used to identify which records would be (or were)
13
16
  considered new, modified or deleted (`loadtarget=`) by creating the following
14
17
  tables:
@@ -17,7 +20,7 @@
17
20
  @li work.outds_del
18
21
  @li work.outds_mod
19
22
 
20
- For example usage, see mp_loadformat.test.sas
23
+ For example usage, see test (under Related Macros)
21
24
 
22
25
  @param [in] libcat The format catalog to be loaded
23
26
  @param [in] libds The staging table to load
@@ -34,6 +37,8 @@
34
37
  @param [in] mdebug= (0) Set to 1 to enable DEBUG messages and preserve outputs
35
38
 
36
39
  <h4> SAS Macros </h4>
40
+ @li mf_existds.sas
41
+ @li mf_existvar.sas
37
42
  @li mf_getuniquename.sas
38
43
  @li mf_nobs.sas
39
44
  @li mp_abort.sas
@@ -84,6 +89,16 @@
84
89
  %let libcat=%scan(&libcat,1,-);
85
90
 
86
91
  /* perform input validations */
92
+ %mp_abort(
93
+ iftrue=(%mf_existds(&libds)=0)
94
+ ,mac=&sysmacroname
95
+ ,msg=%str(&libds could not be found)
96
+ )
97
+ %mp_abort(
98
+ iftrue=(%mf_existvar(&libds,FMTROW)=0)
99
+ ,mac=&sysmacroname
100
+ ,msg=%str(FMTROW not found in &libds)
101
+ )
87
102
  %let err=0;
88
103
  %let msg=0;
89
104
  data _null_;
@@ -104,13 +119,6 @@ data _null_;
104
119
  stop;
105
120
  end;
106
121
  end;
107
- else if name='LIBDS' then do;
108
- if exist(value) le 0 then do;
109
- call symputx('msg',"Unable to open staging table: "!!value);
110
- call symputx('err',1);
111
- stop;
112
- end;
113
- end;
114
122
  else if (name=:'OUTDS' or name in ('DELETE_COL','LOCKLIBDS','AUDITLIBDS'))
115
123
  and missing(value) then do;
116
124
  call symputx('msg',"missing value in var: "!!name);
@@ -118,6 +126,14 @@ data _null_;
118
126
  stop;
119
127
  end;
120
128
  run;
129
+ data _null_;
130
+ set &libds;
131
+ if missing(fmtrow) then do;
132
+ call symputx('msg',"missing fmtrow in format: "!!FMTNAME);
133
+ call symputx('err',1);
134
+ stop;
135
+ end;
136
+ run;
121
137
 
122
138
  %mp_abort(
123
139
  iftrue=(&err ne 0)
@@ -125,6 +141,15 @@ run;
125
141
  ,msg=%str(&msg)
126
142
  )
127
143
 
144
+ %local cnt;
145
+ proc sql noprint;
146
+ select count(distinct catx('|',type,fmtname,fmtrow)) into: cnt from &libds;
147
+ %mp_abort(
148
+ iftrue=(&cnt ne %mf_nobs(&libds))
149
+ ,mac=&sysmacroname
150
+ ,msg=%str(Non-unique primary key on &libds)
151
+ )
152
+
128
153
  /**
129
154
  * First, extract only relevant formats from the catalog
130
155
  */
@@ -178,12 +203,6 @@ data &inlibds/nonote2err;
178
203
  %mp_aligndecimal(end,width=16)
179
204
  end;
180
205
 
181
- /* update row marker - retain new var as fmtrow may already be in libds */
182
- if first.fmtname then row=1;
183
- else row+1;
184
- drop row;
185
- fmtrow=row;
186
-
187
206
  fmthash=%mp_md5(cvars=&cvars, nvars=&nvars);
188
207
  run;
189
208
 
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "^4.4.1"
37
37
  },
38
- "version": "4.48.3"
38
+ "version": "4.49.0"
39
39
  }