@sasjs/core 6.1.4 → 7.0.1
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_existvarlist.sas +16 -6
- package/base/mp_ds2inserts.sas +7 -1
- package/base/mp_stackdiffs.sas +8 -1
- package/base/mp_stripdiffs.sas +13 -0
- package/package.json +1 -1
package/base/mf_existvarlist.sas
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@file
|
|
3
3
|
@brief Checks if a set of variables ALL exist in a data set.
|
|
4
|
-
@details Returns 0 if ANY of the variables do not exist,
|
|
4
|
+
@details Returns 0 if ANY of the variables do not exist, if the dataset
|
|
5
|
+
cannot be opened, if it holds no variables, or if `libds` / `varlist` is
|
|
6
|
+
blank. Returns 1 if they ALL exist. The macro never aborts: a blank input
|
|
7
|
+
answers 0 and the calling program decides whether that is a condition to
|
|
8
|
+
stop on (`mp_abort`) or simply a negative result.
|
|
5
9
|
Usage:
|
|
6
10
|
|
|
7
11
|
%put %mf_existVarList(sashelp.class, age sex name dummyvar);
|
|
@@ -9,9 +13,6 @@
|
|
|
9
13
|
@param [in] libds 2 part dataset or view reference
|
|
10
14
|
@param [in] varlist space separated variable names
|
|
11
15
|
|
|
12
|
-
<h4> SAS Macros </h4>
|
|
13
|
-
@li mf_abort.sas
|
|
14
|
-
|
|
15
16
|
@version 9.2
|
|
16
17
|
@author Allan Bowe
|
|
17
18
|
@cond
|
|
@@ -20,9 +21,12 @@
|
|
|
20
21
|
%macro mf_existvarlist(libds, varlist
|
|
21
22
|
)/*/STORE SOURCE*/;
|
|
22
23
|
|
|
24
|
+
/* nothing to check - answer 0 and let the caller decide whether a blank
|
|
25
|
+
input is a condition worth stopping on */
|
|
23
26
|
%if %str(&libds)=%str() or %str(&varlist)=%str() %then %do;
|
|
24
|
-
%
|
|
25
|
-
|
|
27
|
+
%put %str(WARN)ING: blank libds/varlist in mf_existvarlist;
|
|
28
|
+
0
|
|
29
|
+
%return;
|
|
26
30
|
%end;
|
|
27
31
|
|
|
28
32
|
%local dsid rc i var found;
|
|
@@ -30,10 +34,16 @@
|
|
|
30
34
|
|
|
31
35
|
%if &dsid=0 %then %do;
|
|
32
36
|
%put %str(WARN)ING: unable to open &libds in mf_existvarlist (&dsid);
|
|
37
|
+
/* the failed open reports through SYSMSG, not SYSERR or SYSCC, so the
|
|
38
|
+
return value is the whole signal - and ATTRN and VARNUM return a missing
|
|
39
|
+
value for dsid 0, which would report a match, so return before probing */
|
|
40
|
+
0
|
|
41
|
+
%return;
|
|
33
42
|
%end;
|
|
34
43
|
|
|
35
44
|
%if %sysfunc(attrn(&dsid,NVARS))=0 %then %do;
|
|
36
45
|
%put MF_EXISTVARLIST: No variables in &libds ;
|
|
46
|
+
%let rc=%sysfunc(close(&dsid));
|
|
37
47
|
0
|
|
38
48
|
%return;
|
|
39
49
|
%end;
|
package/base/mp_ds2inserts.sas
CHANGED
|
@@ -149,9 +149,15 @@ data _null_;
|
|
|
149
149
|
%end;
|
|
150
150
|
%if &vtype=N %then %do;
|
|
151
151
|
%if &flavour=SAS %then %do;
|
|
152
|
-
|
|
152
|
+
/* the value becomes a SQL literal, and PUT writes a special missing
|
|
153
|
+
(.A-.Z, ._) as its letter only - which PROC SQL reads as a column
|
|
154
|
+
name, so the leading period is written first */
|
|
155
|
+
if missing(&var) and &var ne . then put "." &var;
|
|
156
|
+
else put &var;
|
|
153
157
|
%end;
|
|
154
158
|
%else %if &flavour=PGSQL %then %do;
|
|
159
|
+
/* Postgres has no special missing values, so any missing numeric
|
|
160
|
+
(including ._ and .A-.Z) is written as NULL */
|
|
155
161
|
if missing(&var) then put 'NULL';
|
|
156
162
|
%if &applydttm=YES and "%substr(&vfmt.xxxxxxxx,1,8)"="DATETIME"
|
|
157
163
|
%then %do;
|
package/base/mp_stackdiffs.sas
CHANGED
|
@@ -575,7 +575,14 @@ select distinct tgtvar_nm into: missvars separated by ' '
|
|
|
575
575
|
qstr=quote(trim(NEWVAL_CHAR));
|
|
576
576
|
put tgtvar_nm '=' qstr;
|
|
577
577
|
end;
|
|
578
|
-
else
|
|
578
|
+
else do;
|
|
579
|
+
/* the value becomes a SQL literal, so a special missing (.A-.Z, ._)
|
|
580
|
+
needs its leading period - PUT writes only the letter, which PROC SQL
|
|
581
|
+
reads as a column name */
|
|
582
|
+
put tgtvar_nm '=' @@;
|
|
583
|
+
if missing(newval_num) and newval_num ne . then put "." newval_num;
|
|
584
|
+
else put newval_num;
|
|
585
|
+
end;
|
|
579
586
|
if comma=' ' then comma=' ,';
|
|
580
587
|
end;
|
|
581
588
|
if last.key_hash then put ' where key_hash=trim("' key_hash '");';
|
package/base/mp_stripdiffs.sas
CHANGED
|
@@ -173,6 +173,9 @@ create table &outds as select "No " as _____DELETE__THIS__RECORD_____
|
|
|
173
173
|
;
|
|
174
174
|
|
|
175
175
|
/* create SAS code to apply to stage_ds */
|
|
176
|
+
/* numeric values become SQL literals, so a special missing (.A-.Z, ._) must
|
|
177
|
+
carry its leading period - PUT writes only the letter, which PROC SQL reads
|
|
178
|
+
as a column name */
|
|
176
179
|
data _null_;
|
|
177
180
|
set &ds1;
|
|
178
181
|
file &fref1 lrecl=33000;
|
|
@@ -188,6 +191,8 @@ data _null_;
|
|
|
188
191
|
cnt=count(oldval_char,'"');
|
|
189
192
|
charval=quote(trim(substr(oldval_char,1,32765-cnt)));
|
|
190
193
|
if tgtvar_type='C' then put charval @@;
|
|
194
|
+
else if missing(oldval_num) and oldval_num ne .
|
|
195
|
+
then put "." oldval_num @@;
|
|
191
196
|
else put oldval_num @@;
|
|
192
197
|
if not last.is_pk then put ',';
|
|
193
198
|
end;
|
|
@@ -197,6 +202,8 @@ data _null_;
|
|
|
197
202
|
cnt=count(oldval_char,'"');
|
|
198
203
|
charval=quote(trim(substr(oldval_char,1,32765-cnt)));
|
|
199
204
|
if tgtvar_type='C' then put charval @@;
|
|
205
|
+
else if missing(oldval_num) and oldval_num ne .
|
|
206
|
+
then put "." oldval_num @@;
|
|
200
207
|
else put oldval_num @@;
|
|
201
208
|
end;
|
|
202
209
|
end;
|
|
@@ -210,6 +217,8 @@ data _null_;
|
|
|
210
217
|
cnt=count(newval_char,'"');
|
|
211
218
|
charval=quote(trim(substr(newval_char,1,32765-cnt)));
|
|
212
219
|
if tgtvar_type='C' then put charval @@;
|
|
220
|
+
else if missing(newval_num) and newval_num ne .
|
|
221
|
+
then put "." newval_num @@;
|
|
213
222
|
else put newval_num @@;
|
|
214
223
|
end;
|
|
215
224
|
else if move_type='D' then do;
|
|
@@ -221,6 +230,8 @@ data _null_;
|
|
|
221
230
|
cnt=count(oldval_char,'"');
|
|
222
231
|
charval=quote(trim(substr(oldval_char,1,32765-cnt)));
|
|
223
232
|
if tgtvar_type='C' then put charval @@;
|
|
233
|
+
else if missing(oldval_num) and oldval_num ne .
|
|
234
|
+
then put "." oldval_num @@;
|
|
224
235
|
else put oldval_num @@;
|
|
225
236
|
end;
|
|
226
237
|
else do;
|
|
@@ -229,6 +240,8 @@ data _null_;
|
|
|
229
240
|
cnt=count(oldval_char,'"');
|
|
230
241
|
charval=quote(trim(substr(oldval_char,1,32765-cnt)));
|
|
231
242
|
if tgtvar_type='C' then put charval @@;
|
|
243
|
+
else if missing(oldval_num) and oldval_num ne .
|
|
244
|
+
then put "." oldval_num @@;
|
|
232
245
|
else put oldval_num @@;
|
|
233
246
|
end;
|
|
234
247
|
end;
|
package/package.json
CHANGED