@sasjs/core 4.7.0 → 4.9.2

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,85 @@
1
+ /**
2
+ @file mp_cntlout.sas
3
+ @brief Creates a cntlout dataset in a consistent format
4
+ @details The dataset produced by proc format in the cntlout option will vary
5
+ according to its contents.
6
+
7
+ When dealing with formats from an ETL perspective (eg in [Data Controller for
8
+ SAS](https://datacontroller.io)), it is important that the output dataset
9
+ has a consistent model (and compariable values).
10
+
11
+ This macro makes use of mddl_sas_cntlout.sas to provide the consistent model,
12
+ and will left-align the start and end values when dealing with numeric ranges
13
+ to enable consistency when checking for differences.
14
+
15
+ usage:
16
+
17
+ %mp_cntlout(libcat=yourlib.cat,cntlout=work.formatexport)
18
+
19
+ @param [in] libcat The library.catalog reference
20
+ @param [in] fmtlist= (0) provide a space separated list of specific formats to
21
+ extract
22
+ @param [in] iftrue= (1=1) A condition under which the macro should be executed
23
+ @param [out] cntlout= (work.fmtextract) Libds reference for the output dataset
24
+
25
+ <h4> SAS Macros </h4>
26
+ @li mddl_sas_cntlout.sas
27
+ @li mf_getuniquename.sas
28
+
29
+ <h4> Related Macros </h4>
30
+ @li mf_getvarformat.sas
31
+ @li mp_getformats.sas
32
+ @li mp_loadformat.sas
33
+ @li mp_ds2fmtds.sas
34
+
35
+ @version 9.2
36
+ @author Allan Bowe
37
+ @cond
38
+ **/
39
+
40
+ %macro mp_cntlout(
41
+ iftrue=(1=1)
42
+ ,libcat=
43
+ ,cntlout=work.fmtextract
44
+ ,fmtlist=0
45
+ )/*/STORE SOURCE*/;
46
+ %local ddlds cntlds i;
47
+
48
+ %if not(%eval(%unquote(&iftrue))) %then %return;
49
+
50
+ %let ddlds=%mf_getuniquename();
51
+ %let cntlds=%mf_getuniquename();
52
+
53
+ %mddl_sas_cntlout(libds=&ddlds)
54
+
55
+ %if %index(&libcat,-)>0 and %scan(&libcat,2,-)=FC %then %do;
56
+ %let libcat=%scan(&libcat,1,-);
57
+ %end;
58
+
59
+ proc format lib=&libcat cntlout=&cntlds;
60
+ %if "&fmtlist" ne "0" %then %do;
61
+ select
62
+ %do i=1 %to %sysfunc(countw(&fmtlist));
63
+ %scan(&fmtlist,&i,%str( ))
64
+ %end;
65
+ ;
66
+ %end;
67
+ run;
68
+
69
+ data &cntlout;
70
+ if 0 then set &ddlds;
71
+ set &cntlds;
72
+ if type="N" then do;
73
+ start=cats(start);
74
+ end=cats(end);
75
+ end;
76
+ run;
77
+ proc sort;
78
+ by fmtname start;
79
+ run;
80
+
81
+ proc sql;
82
+ drop table &ddlds,&cntlds;
83
+
84
+ %mend mp_cntlout;
85
+ /** @endcond */
@@ -113,10 +113,10 @@ create table &outsummary as
113
113
  select &&fmtname&i;
114
114
  run;
115
115
  data &tempds;
116
- length label $256;
116
+ if 0 then set &outdetail;
117
117
  set &tempds;
118
118
  run;
119
- proc append base=&outdetail data=&tempds;
119
+ proc append base=&outdetail data=&tempds ;
120
120
  run;
121
121
  %end;
122
122
  %end;
@@ -38,6 +38,7 @@
38
38
  @li mf_getuniquename.sas
39
39
  @li mf_nobs.sas
40
40
  @li mp_abort.sas
41
+ @li mp_cntlout.sas
41
42
  @li mp_lockanytable.sas
42
43
 
43
44
  <h4> Related Macros </h4>
@@ -66,17 +67,26 @@
66
67
  );
67
68
  /* set up local macro variables and temporary tables (with a prefix) */
68
69
  %local err msg prefix dslist i var fmtlist ibufsize;
69
- %let dslist=base base_fmts template inlibds ds1 stagedata storediffs;
70
+ %let dslist=base_fmts template inlibds ds1 stagedata storediffs;
70
71
  %if &outds_add=0 %then %let dslist=&dslist outds_add;
71
72
  %if &outds_del=0 %then %let dslist=&dslist outds_del;
72
73
  %if &outds_mod=0 %then %let dslist=&dslist outds_mod;
73
- %let prefix=%substr(%mf_getuniquename(),1,22);
74
+ %let prefix=%substr(%mf_getuniquename(),1,21);
74
75
  %do i=1 %to %sysfunc(countw(&dslist));
75
76
  %let var=%scan(&dslist,&i);
76
77
  %local &var;
77
78
  %let &var=%upcase(&prefix._&var);
78
79
  %end;
79
80
 
81
+ /*
82
+ format values can be up to 32767 wide. SQL joins on such a wide column can
83
+ cause buffer issues. Update ibufsize and reset at the end.
84
+ */
85
+ %let ibufsize=%sysfunc(getoption(ibufsize));
86
+ options ibufsize=32767 ;
87
+
88
+ /* in DC, format catalogs maybe specified in the libds with a -FC extension */
89
+ %let libcat=%scan(&libcat,1,-);
80
90
 
81
91
  /* perform input validations */
82
92
  %let err=0;
@@ -125,17 +135,9 @@ run;
125
135
  */
126
136
  proc sql noprint;
127
137
  select distinct fmtname into: fmtlist separated by ' ' from &libds;
128
- proc format lib=&libcat cntlout=&base;
129
- select
130
- /* send formats individually to avoid line truncation in the input stack */
131
- %do i=1 %to %sysfunc(countw(&fmtlist));
132
- %scan(&fmtlist,&i,%str( ))
133
- %end;
134
- ;
135
- run;
136
- proc sort data=&base;
137
- by fmtname start;
138
- run;
138
+
139
+ %mp_cntlout(libcat=&libcat,fmtlist=&fmtlist,cntlout=&base_fmts)
140
+
139
141
 
140
142
  /**
141
143
  * Ensure input table and base_formats have consistent lengths and types
@@ -148,19 +150,12 @@ data &inlibds;
148
150
  if substr(fmtname,1,1)='$' then type='C';
149
151
  else type='N';
150
152
  end;
151
- if type='N' then start=put(input(start,best.),best16.);
152
- run;
153
- data &base_fmts;
154
- if 0 then set &template;
155
- set &base;
153
+ if type='N' then do;
154
+ start=cats(start);
155
+ end=cats(end);
156
+ end;
156
157
  run;
157
158
 
158
- /*
159
- format values can be up to 32767 wide. SQL joins on such a wide column can
160
- cause buffer issues. Update ibufsize and reset at the end.
161
- */
162
- %let ibufsize=%sysfunc(getoption(ibufsize));
163
- options ibufsize=32767 ;
164
159
 
165
160
  /**
166
161
  * Identify new records
@@ -237,9 +232,9 @@ options ibufsize=&ibufsize;
237
232
  %end;
238
233
  %if &locklibds ne 0 %then %do;
239
234
  /* prevent parallel updates */
240
- %mp_lockanytable(LOCK,
241
- lib=%scan(&libcat,1,.)
242
- ,ds=%scan(&libcat,2,.)
235
+ %mp_lockanytable(LOCK
236
+ ,lib=%scan(&libcat,1,.)
237
+ ,ds=%scan(&libcat,2,.)-FC
243
238
  ,ref=MP_LOADFORMAT commencing format load
244
239
  ,ctl_ds=&locklibds
245
240
  )
@@ -250,8 +245,8 @@ options ibufsize=&ibufsize;
250
245
  %if &locklibds ne 0 %then %do;
251
246
  /* unlock the table */
252
247
  %mp_lockanytable(UNLOCK
253
- lib=%scan(&libcat,1,.)
254
- ,ds=%scan(&libcat,2,.)
248
+ ,lib=%scan(&libcat,1,.)
249
+ ,ds=%scan(&libcat,2,.)-FC
255
250
  ,ref=MP_LOADFORMAT completed format load
256
251
  ,ctl_ds=&locklibds
257
252
  )
@@ -259,16 +254,16 @@ options ibufsize=&ibufsize;
259
254
  /* track the changes */
260
255
  %if &auditlibds ne 0 %then %do;
261
256
  %if &locklibds ne 0 %then %do;
262
- %mp_lockanytable(LOCK,
263
- lib=%scan(&auditlibds,1,.)
257
+ %mp_lockanytable(LOCK
258
+ ,lib=%scan(&auditlibds,1,.)
264
259
  ,ds=%scan(&auditlibds,2,.)
265
260
  ,ref=MP_LOADFORMAT commencing audit table load
266
261
  ,ctl_ds=&locklibds
267
262
  )
268
263
  %end;
269
264
 
270
- %mp_storediffs(&libcat
271
- ,&stageds
265
+ %mp_storediffs(&libcat-FC
266
+ ,&inlibds
272
267
  ,FMTNAME START
273
268
  ,delds=&outds_del
274
269
  ,modds=&outds_mod
@@ -279,7 +274,7 @@ options ibufsize=&ibufsize;
279
274
 
280
275
  %if &locklibds ne 0 %then %do;
281
276
  %mp_lockanytable(UNLOCK
282
- lib=%scan(&auditlibds,1,.)
277
+ ,lib=%scan(&auditlibds,1,.)
283
278
  ,ds=%scan(&auditlibds,2,.)
284
279
  ,ref=MP_LOADFORMAT commencing audit table load
285
280
  ,ctl_ds=&locklibds
@@ -48,7 +48,7 @@ data _null_;
48
48
  put name '=' value;
49
49
  run;
50
50
 
51
- %mp_abort(iftrue= (&ds=0 and &action ne MAKETABLE)
51
+ %mp_abort(iftrue= ("&ds"="0" and &action ne MAKETABLE)
52
52
  ,mac=&sysmacroname
53
53
  ,msg=%str(dataset was not provided)
54
54
  )
@@ -37,7 +37,7 @@ run;
37
37
  ,mac=checklock.sas
38
38
  ,msg=Aborting with syscc=&syscc on entry.
39
39
  )
40
- %mp_abort(iftrue= (&libds=0)
40
+ %mp_abort(iftrue= ("&libds"="0")
41
41
  ,mac=&sysmacroname
42
42
  ,msg=%str(libds not provided)
43
43
  )
@@ -46,6 +46,12 @@ run;
46
46
  %let lib=%upcase(%scan(&libds,1,.));
47
47
  %let ds=%upcase(%scan(&libds,2,.));
48
48
 
49
+ /* in DC, format catalogs are passed with a -FC suffix. No saslock here! */
50
+ %if %scan(&libds,2,-)=FC %then %do;
51
+ %put &sysmacroname: Format Catalog detected, no lockfile applied to &libds;
52
+ %return;
53
+ %end;
54
+
49
55
  /* do not proceed if no observations can be processed */
50
56
  %let msg=options obs = 0. syserrortext=%superq(syserrortext);
51
57
  %mp_abort(iftrue= (%sysfunc(getoption(OBS))=0)
@@ -90,7 +90,7 @@
90
90
  %else %let dbg=*;
91
91
 
92
92
  /* set up unique and temporary vars */
93
- %local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist;
93
+ %local ds1 ds2 ds3 ds4 hashkey inds_auto inds_keep dslist vlist;
94
94
  %let ds1=%upcase(work.%mf_getuniquename(prefix=mpsd_ds1));
95
95
  %let ds2=%upcase(work.%mf_getuniquename(prefix=mpsd_ds2));
96
96
  %let ds3=%upcase(work.%mf_getuniquename(prefix=mpsd_ds3));
@@ -144,12 +144,21 @@ proc transpose data=&ds1
144
144
  by &inds_keep &hashkey;
145
145
  var _character_;
146
146
  run;
147
+
148
+ %if %index(&libds,-)>0 and %scan(&libds,2,-)=FC %then %do;
149
+ /* this is a format catalog - cannot query cols directly */
150
+ %let vlist="FMTNAME","START","END","LABEL","MIN","MAX","DEFAULT","LENGTH"
151
+ ,"FUZZ","PREFIX","MULT","FILL","NOEDIT","TYPE","SEXCL","EEXCL","HLO"
152
+ ,"DECSEP","DIG3SEP","DATATYPE","LANGUAGE";
153
+ %end;
154
+ %else %let vlist=%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE);
155
+
147
156
  data &ds4;
148
157
  length &inds_keep $41 tgtvar_nm $32;
149
158
  set &ds2 &ds3 indsname=&inds_auto;
150
159
 
151
160
  tgtvar_nm=upcase(tgtvar_nm);
152
- if tgtvar_nm in (%upcase(%mf_getvarlist(&libds,dlm=%str(,),quote=DOUBLE)));
161
+ if tgtvar_nm in (%upcase(&vlist));
153
162
 
154
163
  if &inds_auto="&ds2" then tgtvar_type='N';
155
164
  else if &inds_auto="&ds3" then tgtvar_type='C';
package/package.json CHANGED
@@ -36,5 +36,5 @@
36
36
  "@sasjs/cli": "3.6.0",
37
37
  "@sasjs/core": "4.4.7"
38
38
  },
39
- "version": "4.7.0"
39
+ "version": "4.9.2"
40
40
  }
@@ -0,0 +1,52 @@
1
+ /**
2
+ @file
3
+ @brief Sets the http headers in the SASjs/server response
4
+ @details For GET requests, SASjs server will use the file generated by this
5
+ macro for setting the appropriate http headers in the response.
6
+
7
+ It works by writing a file to the session directory, that is then ingested by
8
+ the server.
9
+
10
+ The location of this file is driven by the global variable
11
+ `sasjs_stpsrv_header_loc` which is made available in the autoexec.
12
+
13
+ Usage:
14
+
15
+ %mfs_httpheader(Content-type,application/csv)
16
+
17
+ @param [in] header_name Name of the http header to set
18
+ @param [in] header_value Value of the http header to set
19
+
20
+ <h4> Related Macros </h4>
21
+ @li mcf_stpsrv_header.sas
22
+
23
+ @version 9.3
24
+ @author Allan Bowe
25
+
26
+ **/
27
+
28
+ %macro mfs_httpheader(header_name
29
+ ,header_value
30
+ )/*/STORE SOURCE*/;
31
+ %local fref fid i;
32
+
33
+ %if %sysfunc(filename(fref,&sasjs_stpsrv_header_loc)) ne 0 %then %do;
34
+ %put &=fref &=sasjs_stpsrv_header_loc;
35
+ %put %str(ERR)OR: %sysfunc(sysmsg());
36
+ %return;
37
+ %end;
38
+
39
+ %let fid=%sysfunc(fopen(&fref,A));
40
+
41
+ %if &fid=0 %then %do;
42
+ %put %str(ERR)OR: %sysfunc(sysmsg());
43
+ %return;
44
+ %end;
45
+
46
+ %let rc=%sysfunc(fput(&fid,%str(&header_name): %str(&header_value)));
47
+ %let rc=%sysfunc(fwrite(&fid));
48
+
49
+ %let rc=%sysfunc(fclose(&fid));
50
+ %let rc=%sysfunc(filename(&fref));
51
+
52
+ %mend mfs_httpheader;
@@ -33,8 +33,9 @@
33
33
  `,"$tablename":{"formats":{"col1":"$CHAR1"},"types":{"COL1":"C"}}`
34
34
 
35
35
  <h4> SAS Macros </h4>
36
- @li mp_jsonout.sas
37
36
  @li mf_getuser.sas
37
+ @li mp_jsonout.sas
38
+ @li mfs_httpheader.sas
38
39
 
39
40
  <h4> Related Macros </h4>
40
41
  @li mv_webout.sas
@@ -86,11 +87,11 @@
86
87
  /* fix encoding */
87
88
  OPTIONS NOBOMFILE;
88
89
 
90
+ /* set the header */
91
+ %mfs_httpheader(Content-type,application/json)
92
+
89
93
  /* setup json */
90
94
  data _null_;file &fref encoding='utf-8' termstr=lf;
91
- %if %str(&_debug) ge 131 %then %do;
92
- put '>>weboutBEGIN<<';
93
- %end;
94
95
  put '{"SYSDATE" : "' "&SYSDATE" '"';
95
96
  put ',"SYSTIME" : "' "&SYSTIME" '"';
96
97
  run;
@@ -170,9 +171,6 @@
170
171
  memsize=quote(cats(memsize));
171
172
  put ',"MEMSIZE" : ' memsize;
172
173
  put "}" @;
173
- %if %str(&_debug) ge 131 %then %do;
174
- put '>>weboutEND<<';
175
- %end;
176
174
  run;
177
175
  %end;
178
176