@sasjs/core 4.19.0 → 4.21.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_getuniquefileref.sas +5 -3
- package/base/mf_isint.sas +4 -1
- package/base/mp_chop.sas +194 -0
- package/base/mp_createwebservice.sas +13 -2
- package/base/mp_gsubfile.sas +1 -1
- package/base/mp_jsonout.sas +1 -1
- package/base/mp_replace.sas +4 -2
- package/base/mp_streamfile.sas +29 -21
- package/base/mp_testservice.sas +27 -4
- package/lua/ml_gsubfile.sas +8 -0
- package/lua/ml_json.sas +8 -0
- package/meta/mm_createwebservice.sas +20 -20
- package/package.json +1 -1
- package/server/mfs_httpheader.sas +2 -1
- package/server/ms_createfile.sas +8 -4
- package/server/ms_createwebservice.sas +532 -0
- package/server/ms_runstp.sas +128 -7
- package/server/ms_testservice.sas +152 -0
- package/server/ms_webout.sas +9 -8
- package/viya/mv_createwebservice.sas +20 -20
package/server/ms_createfile.sas
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
@li mf_getuniquefileref.sas
|
|
22
22
|
@li mf_getuniquename.sas
|
|
23
23
|
@li mp_abort.sas
|
|
24
|
+
@li ms_deletefile.sas
|
|
24
25
|
|
|
25
26
|
**/
|
|
26
27
|
|
|
@@ -29,6 +30,9 @@
|
|
|
29
30
|
,mdebug=0
|
|
30
31
|
);
|
|
31
32
|
|
|
33
|
+
/* first, delete in case it exists */
|
|
34
|
+
%ms_deletefile(&driveloc,mdebug=&mdebug)
|
|
35
|
+
|
|
32
36
|
%local fname0 fname1 fname2 boundary fname statcd msg optval;
|
|
33
37
|
%let fname0=%mf_getuniquefileref();
|
|
34
38
|
%let fname1=%mf_getuniquefileref();
|
|
@@ -40,8 +44,8 @@
|
|
|
40
44
|
options nobomfile;
|
|
41
45
|
|
|
42
46
|
data _null_;
|
|
43
|
-
file &fname0 termstr=crlf;
|
|
44
|
-
infile &inref end=eof;
|
|
47
|
+
file &fname0 termstr=crlf lrecl=32767;
|
|
48
|
+
infile &inref end=eof lrecl=32767;
|
|
45
49
|
if _n_ = 1 then do;
|
|
46
50
|
put "--&boundary.";
|
|
47
51
|
put 'Content-Disposition: form-data; name="filePath"';
|
|
@@ -70,11 +74,11 @@ run;
|
|
|
70
74
|
|
|
71
75
|
%if &mdebug=1 %then %do;
|
|
72
76
|
data _null_;
|
|
73
|
-
infile &fname0;
|
|
77
|
+
infile &fname0 lrecl=32767;
|
|
74
78
|
input;
|
|
75
79
|
put _infile_;
|
|
76
80
|
data _null_;
|
|
77
|
-
infile &fname1;
|
|
81
|
+
infile &fname1 lrecl=32767;
|
|
78
82
|
input;
|
|
79
83
|
put _infile_;
|
|
80
84
|
run;
|
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file ms_createwebservice.sas
|
|
3
|
+
@brief Create a Web-Ready Stored Program
|
|
4
|
+
@details This macro creates a Stored Program along with the necessary precode
|
|
5
|
+
to enable the %webout() macro
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
<code>
|
|
9
|
+
%* compile macros ;
|
|
10
|
+
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
|
11
|
+
%inc mc;
|
|
12
|
+
|
|
13
|
+
%* parmcards lets us write to a text file from open code ;
|
|
14
|
+
filename ft15f001 temp;
|
|
15
|
+
parmcards4;
|
|
16
|
+
%webout(FETCH)
|
|
17
|
+
%* do some sas, any inputs are now already WORK tables;
|
|
18
|
+
data example1 example2;
|
|
19
|
+
set sashelp.class;
|
|
20
|
+
run;
|
|
21
|
+
%* send data back;
|
|
22
|
+
%webout(OPEN)
|
|
23
|
+
%webout(ARR,example1) * Array format, fast, suitable for large tables ;
|
|
24
|
+
%webout(OBJ,example2) * Object format, easier to work with ;
|
|
25
|
+
%webout(CLOSE)
|
|
26
|
+
;;;;
|
|
27
|
+
%ms_createwebservice(path=/Public/app/common,name=appInit,code=ft15f001)
|
|
28
|
+
|
|
29
|
+
</code>
|
|
30
|
+
|
|
31
|
+
For more examples of using these web services with the SASjs Adapter, see:
|
|
32
|
+
https://github.com/sasjs/adapter#readme
|
|
33
|
+
|
|
34
|
+
@param [in] path= (0) The full SASjs Drive path in which to create the service
|
|
35
|
+
@param [in] name= Stored Program name
|
|
36
|
+
@param [in] desc= The description of the service (not implemented yet)
|
|
37
|
+
@param [in] precode= Space separated list of filerefs, pointing to the code
|
|
38
|
+
that needs to be attached to the beginning of the service (optional)
|
|
39
|
+
@param [in] code= (ft15f001) Space seperated fileref(s) of the actual code to
|
|
40
|
+
be added
|
|
41
|
+
@param [in] mDebug= (0) set to 1 to show debug messages in the log
|
|
42
|
+
|
|
43
|
+
<h4> SAS Macros </h4>
|
|
44
|
+
@li ms_createfile.sas
|
|
45
|
+
@li mf_getuser.sas
|
|
46
|
+
@li mf_getuniquename.sas
|
|
47
|
+
@li mf_getuniquefileref.sas
|
|
48
|
+
@li mp_abort.sas
|
|
49
|
+
|
|
50
|
+
<h4> Related Files </h4>
|
|
51
|
+
@li ms_createwebservice.test.sas
|
|
52
|
+
|
|
53
|
+
@version 9.2
|
|
54
|
+
@author Allan Bowe
|
|
55
|
+
|
|
56
|
+
**/
|
|
57
|
+
|
|
58
|
+
%macro ms_createwebservice(path=0
|
|
59
|
+
,name=initService
|
|
60
|
+
,precode=
|
|
61
|
+
,code=ft15f001
|
|
62
|
+
,desc=Not currently used
|
|
63
|
+
,mDebug=0
|
|
64
|
+
)/*/STORE SOURCE*/;
|
|
65
|
+
|
|
66
|
+
%local dbg;
|
|
67
|
+
%if &mdebug=1 %then %do;
|
|
68
|
+
%put &sysmacroname entry vars:;
|
|
69
|
+
%put _local_;
|
|
70
|
+
%end;
|
|
71
|
+
%else %let dbg=*;
|
|
72
|
+
|
|
73
|
+
%mp_abort(iftrue=(&syscc ge 4 )
|
|
74
|
+
,mac=ms_createwebservice
|
|
75
|
+
,msg=%str(syscc=&syscc on macro entry)
|
|
76
|
+
)
|
|
77
|
+
%mp_abort(iftrue=("&path"="0")
|
|
78
|
+
,mac=ms_createwebservice
|
|
79
|
+
,msg=%str(Path not provided)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
/* remove any trailing slash */
|
|
83
|
+
%if "%substr(&path,%length(&path),1)" = "/" %then
|
|
84
|
+
%let path=%substr(&path,1,%length(&path)-1);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Add webout macro
|
|
88
|
+
* These put statements are auto generated - to change the macro, change the
|
|
89
|
+
* source (ms_webout) and run `build.py`
|
|
90
|
+
*/
|
|
91
|
+
%local sasjsref;
|
|
92
|
+
%let sasjsref=%mf_getuniquefileref();
|
|
93
|
+
data _null_;
|
|
94
|
+
file &sasjsref termstr=crlf lrecl=512;
|
|
95
|
+
put "/* Created on %sysfunc(datetime(),datetime19.) by %mf_getuser() */";
|
|
96
|
+
/* WEBOUT BEGIN */
|
|
97
|
+
put ' ';
|
|
98
|
+
put '%macro mp_jsonout(action,ds,jref=_webout,dslabel=,fmt=Y ';
|
|
99
|
+
put ' ,engine=DATASTEP ';
|
|
100
|
+
put ' ,missing=NULL ';
|
|
101
|
+
put ' ,showmeta=NO ';
|
|
102
|
+
put ')/*/STORE SOURCE*/; ';
|
|
103
|
+
put '%local tempds colinfo fmtds i numcols; ';
|
|
104
|
+
put '%let numcols=0; ';
|
|
105
|
+
put ' ';
|
|
106
|
+
put '%if &action=OPEN %then %do; ';
|
|
107
|
+
put ' options nobomfile; ';
|
|
108
|
+
put ' data _null_;file &jref encoding=''utf-8'' lrecl=200; ';
|
|
109
|
+
put ' put ''{"PROCESSED_DTTM" : "'' "%sysfunc(datetime(),E8601DT26.6)" ''"''; ';
|
|
110
|
+
put ' run; ';
|
|
111
|
+
put '%end; ';
|
|
112
|
+
put '%else %if (&action=ARR or &action=OBJ) %then %do; ';
|
|
113
|
+
put ' options validvarname=upcase; ';
|
|
114
|
+
put ' data _null_; file &jref encoding=''utf-8'' mod; ';
|
|
115
|
+
put ' put ", ""%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":"; ';
|
|
116
|
+
put ' ';
|
|
117
|
+
put ' /* grab col defs */ ';
|
|
118
|
+
put ' proc contents noprint data=&ds ';
|
|
119
|
+
put ' out=_data_(keep=name type length format formatl formatd varnum label); ';
|
|
120
|
+
put ' run; ';
|
|
121
|
+
put ' %let colinfo=%scan(&syslast,2,.); ';
|
|
122
|
+
put ' proc sort data=&colinfo; ';
|
|
123
|
+
put ' by varnum; ';
|
|
124
|
+
put ' run; ';
|
|
125
|
+
put ' /* move meta to mac vars */ ';
|
|
126
|
+
put ' data _null_; ';
|
|
127
|
+
put ' if _n_=1 then call symputx(''numcols'',nobs,''l''); ';
|
|
128
|
+
put ' set &colinfo end=last nobs=nobs; ';
|
|
129
|
+
put ' name=upcase(name); ';
|
|
130
|
+
put ' /* fix formats */ ';
|
|
131
|
+
put ' if type=2 or type=6 then do; ';
|
|
132
|
+
put ' typelong=''char''; ';
|
|
133
|
+
put ' length fmt $49.; ';
|
|
134
|
+
put ' if format='''' then fmt=cats(''$'',length,''.''); ';
|
|
135
|
+
put ' else if formatl=0 then fmt=cats(format,''.''); ';
|
|
136
|
+
put ' else fmt=cats(format,formatl,''.''); ';
|
|
137
|
+
put ' newlen=max(formatl,length); ';
|
|
138
|
+
put ' end; ';
|
|
139
|
+
put ' else do; ';
|
|
140
|
+
put ' typelong=''num''; ';
|
|
141
|
+
put ' if format='''' then fmt=''best.''; ';
|
|
142
|
+
put ' else if formatl=0 then fmt=cats(format,''.''); ';
|
|
143
|
+
put ' else if formatd=0 then fmt=cats(format,formatl,''.''); ';
|
|
144
|
+
put ' else fmt=cats(format,formatl,''.'',formatd); ';
|
|
145
|
+
put ' /* needs to be wide, for datetimes etc */ ';
|
|
146
|
+
put ' newlen=max(length,formatl,24); ';
|
|
147
|
+
put ' end; ';
|
|
148
|
+
put ' /* 32 char unique name */ ';
|
|
149
|
+
put ' newname=''sasjs''!!substr(cats(put(md5(name),$hex32.)),1,27); ';
|
|
150
|
+
put ' ';
|
|
151
|
+
put ' call symputx(cats(''name'',_n_),name,''l''); ';
|
|
152
|
+
put ' call symputx(cats(''newname'',_n_),newname,''l''); ';
|
|
153
|
+
put ' call symputx(cats(''len'',_n_),newlen,''l''); ';
|
|
154
|
+
put ' call symputx(cats(''length'',_n_),length,''l''); ';
|
|
155
|
+
put ' call symputx(cats(''fmt'',_n_),fmt,''l''); ';
|
|
156
|
+
put ' call symputx(cats(''type'',_n_),type,''l''); ';
|
|
157
|
+
put ' call symputx(cats(''typelong'',_n_),typelong,''l''); ';
|
|
158
|
+
put ' call symputx(cats(''label'',_n_),coalescec(label,name),''l''); ';
|
|
159
|
+
put ' run; ';
|
|
160
|
+
put ' ';
|
|
161
|
+
put ' %let tempds=%substr(_%sysfunc(compress(%sysfunc(uuidgen()),-)),1,32); ';
|
|
162
|
+
put ' ';
|
|
163
|
+
put ' %if &engine=PROCJSON %then %do; ';
|
|
164
|
+
put ' %if &missing=STRING %then %do; ';
|
|
165
|
+
put ' %put &sysmacroname: Special Missings not supported in proc json.; ';
|
|
166
|
+
put ' %put &sysmacroname: Switching to DATASTEP engine; ';
|
|
167
|
+
put ' %goto datastep; ';
|
|
168
|
+
put ' %end; ';
|
|
169
|
+
put ' data &tempds;set &ds; ';
|
|
170
|
+
put ' %if &fmt=N %then format _numeric_ best32.;; ';
|
|
171
|
+
put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
|
|
172
|
+
put ' proc json out=&jref pretty ';
|
|
173
|
+
put ' %if &action=ARR %then nokeys ; ';
|
|
174
|
+
put ' ;export &tempds / nosastags fmtnumeric; ';
|
|
175
|
+
put ' run; ';
|
|
176
|
+
put ' %end; ';
|
|
177
|
+
put ' %else %if &engine=DATASTEP %then %do; ';
|
|
178
|
+
put ' %datastep: ';
|
|
179
|
+
put ' %if %sysfunc(exist(&ds)) ne 1 & %sysfunc(exist(&ds,VIEW)) ne 1 ';
|
|
180
|
+
put ' %then %do; ';
|
|
181
|
+
put ' %put &sysmacroname: &ds NOT FOUND!!!; ';
|
|
182
|
+
put ' %return; ';
|
|
183
|
+
put ' %end; ';
|
|
184
|
+
put ' ';
|
|
185
|
+
put ' %if &fmt=Y %then %do; ';
|
|
186
|
+
put ' data _data_; ';
|
|
187
|
+
put ' /* rename on entry */ ';
|
|
188
|
+
put ' set &ds(rename=( ';
|
|
189
|
+
put ' %do i=1 %to &numcols; ';
|
|
190
|
+
put ' &&name&i=&&newname&i ';
|
|
191
|
+
put ' %end; ';
|
|
192
|
+
put ' )); ';
|
|
193
|
+
put ' %do i=1 %to &numcols; ';
|
|
194
|
+
put ' length &&name&i $&&len&i; ';
|
|
195
|
+
put ' %if &&typelong&i=num %then %do; ';
|
|
196
|
+
put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
|
|
197
|
+
put ' %end; ';
|
|
198
|
+
put ' %else %do; ';
|
|
199
|
+
put ' &&name&i=put(&&newname&i,&&fmt&i); ';
|
|
200
|
+
put ' %end; ';
|
|
201
|
+
put ' drop &&newname&i; ';
|
|
202
|
+
put ' %end; ';
|
|
203
|
+
put ' if _error_ then call symputx(''syscc'',1012); ';
|
|
204
|
+
put ' run; ';
|
|
205
|
+
put ' %let fmtds=&syslast; ';
|
|
206
|
+
put ' %end; ';
|
|
207
|
+
put ' ';
|
|
208
|
+
put ' proc format; /* credit yabwon for special null removal */ ';
|
|
209
|
+
put ' value bart (default=40) ';
|
|
210
|
+
put ' %if &missing=NULL %then %do; ';
|
|
211
|
+
put ' ._ - .z = null ';
|
|
212
|
+
put ' %end; ';
|
|
213
|
+
put ' %else %do; ';
|
|
214
|
+
put ' ._ = [quote()] ';
|
|
215
|
+
put ' . = null ';
|
|
216
|
+
put ' .a - .z = [quote()] ';
|
|
217
|
+
put ' %end; ';
|
|
218
|
+
put ' other = [best.]; ';
|
|
219
|
+
put ' ';
|
|
220
|
+
put ' data &tempds; ';
|
|
221
|
+
put ' attrib _all_ label=''''; ';
|
|
222
|
+
put ' %do i=1 %to &numcols; ';
|
|
223
|
+
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
|
224
|
+
put ' length &&name&i $32767; ';
|
|
225
|
+
put ' format &&name&i $32767.; ';
|
|
226
|
+
put ' %end; ';
|
|
227
|
+
put ' %end; ';
|
|
228
|
+
put ' %if &fmt=Y %then %do; ';
|
|
229
|
+
put ' set &fmtds; ';
|
|
230
|
+
put ' %end; ';
|
|
231
|
+
put ' %else %do; ';
|
|
232
|
+
put ' set &ds; ';
|
|
233
|
+
put ' %end; ';
|
|
234
|
+
put ' format _numeric_ bart.; ';
|
|
235
|
+
put ' %do i=1 %to &numcols; ';
|
|
236
|
+
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
|
237
|
+
put ' if findc(&&name&i,''"\''!!''0A0D09000E0F01021011''x) then do; ';
|
|
238
|
+
put ' &&name&i=''"''!!trim( ';
|
|
239
|
+
put ' prxchange(''s/"/\\"/'',-1, /* double quote */ ';
|
|
240
|
+
put ' prxchange(''s/\x0A/\n/'',-1, /* new line */ ';
|
|
241
|
+
put ' prxchange(''s/\x0D/\r/'',-1, /* carriage return */ ';
|
|
242
|
+
put ' prxchange(''s/\x09/\\t/'',-1, /* tab */ ';
|
|
243
|
+
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
|
244
|
+
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
|
245
|
+
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
|
246
|
+
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
|
247
|
+
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
|
248
|
+
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
|
249
|
+
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
|
250
|
+
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
|
251
|
+
put ' ))))))))))))!!''"''; ';
|
|
252
|
+
put ' end; ';
|
|
253
|
+
put ' else &&name&i=quote(cats(&&name&i)); ';
|
|
254
|
+
put ' %end; ';
|
|
255
|
+
put ' %end; ';
|
|
256
|
+
put ' run; ';
|
|
257
|
+
put ' ';
|
|
258
|
+
put ' /* write to temp loc to avoid _webout truncation ';
|
|
259
|
+
put ' - https://support.sas.com/kb/49/325.html */ ';
|
|
260
|
+
put ' filename _sjs temp lrecl=131068 encoding=''utf-8''; ';
|
|
261
|
+
put ' data _null_; file _sjs lrecl=131068 encoding=''utf-8'' mod ; ';
|
|
262
|
+
put ' if _n_=1 then put "["; ';
|
|
263
|
+
put ' set &tempds; ';
|
|
264
|
+
put ' if _n_>1 then put "," @; put ';
|
|
265
|
+
put ' %if &action=ARR %then "[" ; %else "{" ; ';
|
|
266
|
+
put ' %do i=1 %to &numcols; ';
|
|
267
|
+
put ' %if &i>1 %then "," ; ';
|
|
268
|
+
put ' %if &action=OBJ %then """&&name&i"":" ; ';
|
|
269
|
+
put ' &&name&i ';
|
|
270
|
+
put ' %end; ';
|
|
271
|
+
put ' %if &action=ARR %then "]" ; %else "}" ; ; ';
|
|
272
|
+
put ' /* now write the long strings to _webout 1 byte at a time */ ';
|
|
273
|
+
put ' data _null_; ';
|
|
274
|
+
put ' length filein 8 fileid 8; ';
|
|
275
|
+
put ' filein=fopen("_sjs",''I'',1,''B''); ';
|
|
276
|
+
put ' fileid=fopen("&jref",''A'',1,''B''); ';
|
|
277
|
+
put ' rec=''20''x; ';
|
|
278
|
+
put ' do while(fread(filein)=0); ';
|
|
279
|
+
put ' rc=fget(filein,rec,1); ';
|
|
280
|
+
put ' rc=fput(fileid, rec); ';
|
|
281
|
+
put ' rc=fwrite(fileid); ';
|
|
282
|
+
put ' end; ';
|
|
283
|
+
put ' /* close out the table */ ';
|
|
284
|
+
put ' rc=fput(fileid, "]"); ';
|
|
285
|
+
put ' rc=fwrite(fileid); ';
|
|
286
|
+
put ' rc=fclose(filein); ';
|
|
287
|
+
put ' rc=fclose(fileid); ';
|
|
288
|
+
put ' run; ';
|
|
289
|
+
put ' filename _sjs clear; ';
|
|
290
|
+
put ' %end; ';
|
|
291
|
+
put ' ';
|
|
292
|
+
put ' proc sql; ';
|
|
293
|
+
put ' drop table &colinfo, &tempds; ';
|
|
294
|
+
put ' ';
|
|
295
|
+
put ' %if &showmeta=YES %then %do; ';
|
|
296
|
+
put ' data _null_; file &jref encoding=''utf-8'' mod; ';
|
|
297
|
+
put ' put ", ""$%lowcase(%sysfunc(coalescec(&dslabel,&ds)))"":{""vars"":{"; ';
|
|
298
|
+
put ' do i=1 to &numcols; ';
|
|
299
|
+
put ' name=quote(trim(symget(cats(''name'',i)))); ';
|
|
300
|
+
put ' format=quote(trim(symget(cats(''fmt'',i)))); ';
|
|
301
|
+
put ' label=quote(trim(symget(cats(''label'',i)))); ';
|
|
302
|
+
put ' length=quote(trim(symget(cats(''length'',i)))); ';
|
|
303
|
+
put ' type=quote(trim(symget(cats(''typelong'',i)))); ';
|
|
304
|
+
put ' if i>1 then put "," @@; ';
|
|
305
|
+
put ' put name '':{"format":'' format '',"label":'' label ';
|
|
306
|
+
put ' '',"length":'' length '',"type":'' type ''}''; ';
|
|
307
|
+
put ' end; ';
|
|
308
|
+
put ' put ''}}''; ';
|
|
309
|
+
put ' run; ';
|
|
310
|
+
put ' %end; ';
|
|
311
|
+
put '%end; ';
|
|
312
|
+
put ' ';
|
|
313
|
+
put '%else %if &action=CLOSE %then %do; ';
|
|
314
|
+
put ' data _null_; file &jref encoding=''utf-8'' mod ; ';
|
|
315
|
+
put ' put "}"; ';
|
|
316
|
+
put ' run; ';
|
|
317
|
+
put '%end; ';
|
|
318
|
+
put '%mend mp_jsonout; ';
|
|
319
|
+
put ' ';
|
|
320
|
+
put '%macro mf_getuser(type=META ';
|
|
321
|
+
put ')/*/STORE SOURCE*/; ';
|
|
322
|
+
put ' %local user metavar; ';
|
|
323
|
+
put ' %if &type=OS %then %let metavar=_secureusername; ';
|
|
324
|
+
put ' %else %let metavar=_metaperson; ';
|
|
325
|
+
put ' ';
|
|
326
|
+
put ' %if %symexist(SYS_COMPUTE_SESSION_OWNER) %then %let user=&SYS_COMPUTE_SESSION_OWNER; ';
|
|
327
|
+
put ' %else %if %symexist(&metavar) %then %do; ';
|
|
328
|
+
put ' %if %length(&&&metavar)=0 %then %let user=&sysuserid; ';
|
|
329
|
+
put ' /* sometimes SAS will add @domain extension - remove for consistency */ ';
|
|
330
|
+
put ' /* but be sure to quote in case of usernames with commas */ ';
|
|
331
|
+
put ' %else %let user=%unquote(%scan(%quote(&&&metavar),1,@)); ';
|
|
332
|
+
put ' %end; ';
|
|
333
|
+
put ' %else %let user=&sysuserid; ';
|
|
334
|
+
put ' ';
|
|
335
|
+
put ' %quote(&user) ';
|
|
336
|
+
put ' ';
|
|
337
|
+
put '%mend mf_getuser; ';
|
|
338
|
+
put ' ';
|
|
339
|
+
put '%macro ms_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL ';
|
|
340
|
+
put ' ,showmeta=NO ';
|
|
341
|
+
put '); ';
|
|
342
|
+
put '%global _webin_file_count _webin_fileref1 _webin_name1 _program _debug ';
|
|
343
|
+
put ' sasjs_tables; ';
|
|
344
|
+
put ' ';
|
|
345
|
+
put '%local i tempds; ';
|
|
346
|
+
put '%let action=%upcase(&action); ';
|
|
347
|
+
put ' ';
|
|
348
|
+
put '%if &action=FETCH %then %do; ';
|
|
349
|
+
put ' %if %str(&_debug) ge 131 %then %do; ';
|
|
350
|
+
put ' options mprint notes mprintnest; ';
|
|
351
|
+
put ' %end; ';
|
|
352
|
+
put ' %let _webin_file_count=%eval(&_webin_file_count+0); ';
|
|
353
|
+
put ' /* now read in the data */ ';
|
|
354
|
+
put ' %do i=1 %to &_webin_file_count; ';
|
|
355
|
+
put ' %if &_webin_file_count=1 %then %do; ';
|
|
356
|
+
put ' %let _webin_fileref1=&_webin_fileref; ';
|
|
357
|
+
put ' %let _webin_name1=&_webin_name; ';
|
|
358
|
+
put ' %end; ';
|
|
359
|
+
put ' data _null_; ';
|
|
360
|
+
put ' infile &&_webin_fileref&i termstr=crlf lrecl=32767; ';
|
|
361
|
+
put ' input; ';
|
|
362
|
+
put ' call symputx(''input_statement'',_infile_); ';
|
|
363
|
+
put ' putlog "&&_webin_name&i input statement: " _infile_; ';
|
|
364
|
+
put ' stop; ';
|
|
365
|
+
put ' data &&_webin_name&i; ';
|
|
366
|
+
put ' infile &&_webin_fileref&i firstobs=2 dsd termstr=crlf encoding=''utf-8'' ';
|
|
367
|
+
put ' lrecl=32767; ';
|
|
368
|
+
put ' input &input_statement; ';
|
|
369
|
+
put ' %if %str(&_debug) ge 131 %then %do; ';
|
|
370
|
+
put ' if _n_<20 then putlog _infile_; ';
|
|
371
|
+
put ' %end; ';
|
|
372
|
+
put ' run; ';
|
|
373
|
+
put ' %let sasjs_tables=&sasjs_tables &&_webin_name&i; ';
|
|
374
|
+
put ' %end; ';
|
|
375
|
+
put '%end; ';
|
|
376
|
+
put ' ';
|
|
377
|
+
put '%else %if &action=OPEN %then %do; ';
|
|
378
|
+
put ' /* fix encoding and ensure enough lrecl */ ';
|
|
379
|
+
put ' OPTIONS NOBOMFILE lrecl=32767; ';
|
|
380
|
+
put ' ';
|
|
381
|
+
put ' /* set the header */ ';
|
|
382
|
+
put ' %mfs_httpheader(Content-type,application/json) ';
|
|
383
|
+
put ' ';
|
|
384
|
+
put ' /* setup json. */ ';
|
|
385
|
+
put ' data _null_;file &fref encoding=''utf-8'' termstr=lf ; ';
|
|
386
|
+
put ' put ''{"SYSDATE" : "'' "&SYSDATE" ''"''; ';
|
|
387
|
+
put ' put '',"SYSTIME" : "'' "&SYSTIME" ''"''; ';
|
|
388
|
+
put ' run; ';
|
|
389
|
+
put ' ';
|
|
390
|
+
put '%end; ';
|
|
391
|
+
put ' ';
|
|
392
|
+
put '%else %if &action=ARR or &action=OBJ %then %do; ';
|
|
393
|
+
put ' %mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt,jref=&fref ';
|
|
394
|
+
put ' ,engine=DATASTEP,missing=&missing,showmeta=&showmeta ';
|
|
395
|
+
put ' ) ';
|
|
396
|
+
put '%end; ';
|
|
397
|
+
put '%else %if &action=CLOSE %then %do; ';
|
|
398
|
+
put ' %if %str(&_debug) ge 131 %then %do; ';
|
|
399
|
+
put ' /* if debug mode, send back first 10 records of each work table also */ ';
|
|
400
|
+
put ' options obs=10; ';
|
|
401
|
+
put ' data;run;%let tempds=%scan(&syslast,2,.); ';
|
|
402
|
+
put ' ods output Members=&tempds; ';
|
|
403
|
+
put ' proc datasets library=WORK memtype=data; ';
|
|
404
|
+
put ' %local wtcnt;%let wtcnt=0; ';
|
|
405
|
+
put ' data _null_; ';
|
|
406
|
+
put ' set &tempds; ';
|
|
407
|
+
put ' if not (upcase(name) =:"DATA"); /* ignore temp datasets */ ';
|
|
408
|
+
put ' if not (upcase(name)=:"_DATA_"); ';
|
|
409
|
+
put ' i+1; ';
|
|
410
|
+
put ' call symputx(cats(''wt'',i),name,''l''); ';
|
|
411
|
+
put ' call symputx(''wtcnt'',i,''l''); ';
|
|
412
|
+
put ' data _null_; file &fref mod encoding=''utf-8'' termstr=lf; ';
|
|
413
|
+
put ' put ",""WORK"":{"; ';
|
|
414
|
+
put ' %do i=1 %to &wtcnt; ';
|
|
415
|
+
put ' %let wt=&&wt&i; ';
|
|
416
|
+
put ' data _null_; file &fref mod encoding=''utf-8'' termstr=lf; ';
|
|
417
|
+
put ' dsid=open("WORK.&wt",''is''); ';
|
|
418
|
+
put ' nlobs=attrn(dsid,''NLOBS''); ';
|
|
419
|
+
put ' nvars=attrn(dsid,''NVARS''); ';
|
|
420
|
+
put ' rc=close(dsid); ';
|
|
421
|
+
put ' if &i>1 then put '',''@; ';
|
|
422
|
+
put ' put " ""&wt"" : {"; ';
|
|
423
|
+
put ' put ''"nlobs":'' nlobs; ';
|
|
424
|
+
put ' put '',"nvars":'' nvars; ';
|
|
425
|
+
put ' %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,showmeta=YES) ';
|
|
426
|
+
put ' data _null_; file &fref mod encoding=''utf-8'' termstr=lf; ';
|
|
427
|
+
put ' put "}"; ';
|
|
428
|
+
put ' %end; ';
|
|
429
|
+
put ' data _null_; file &fref mod encoding=''utf-8'' termstr=lf; ';
|
|
430
|
+
put ' put "}"; ';
|
|
431
|
+
put ' run; ';
|
|
432
|
+
put ' %end; ';
|
|
433
|
+
put ' /* close off json */ ';
|
|
434
|
+
put ' data _null_;file &fref mod encoding=''utf-8'' termstr=lf lrecl=32767; ';
|
|
435
|
+
put ' _PROGRAM=quote(trim(resolve(symget(''_PROGRAM'')))); ';
|
|
436
|
+
put ' put ",""SYSUSERID"" : ""&sysuserid"" "; ';
|
|
437
|
+
put ' put ",""MF_GETUSER"" : ""%mf_getuser()"" "; ';
|
|
438
|
+
put ' put ",""_DEBUG"" : ""&_debug"" "; ';
|
|
439
|
+
put ' put '',"_PROGRAM" : '' _PROGRAM ; ';
|
|
440
|
+
put ' put ",""SYSCC"" : ""&syscc"" "; ';
|
|
441
|
+
put ' syserrortext=quote(cats(symget(''SYSERRORTEXT''))); ';
|
|
442
|
+
put ' put '',"SYSERRORTEXT" : '' syserrortext; ';
|
|
443
|
+
put ' SYSHOSTINFOLONG=quote(trim(symget(''SYSHOSTINFOLONG''))); ';
|
|
444
|
+
put ' put '',"SYSHOSTINFOLONG" : '' SYSHOSTINFOLONG; ';
|
|
445
|
+
put ' put ",""SYSHOSTNAME"" : ""&syshostname"" "; ';
|
|
446
|
+
put ' put ",""SYSPROCESSID"" : ""&SYSPROCESSID"" "; ';
|
|
447
|
+
put ' put ",""SYSPROCESSMODE"" : ""&SYSPROCESSMODE"" "; ';
|
|
448
|
+
put ' length SYSPROCESSNAME $512; ';
|
|
449
|
+
put ' SYSPROCESSNAME=quote(urlencode(cats(SYSPROCESSNAME))); ';
|
|
450
|
+
put ' put ",""SYSPROCESSNAME"" : " SYSPROCESSNAME; ';
|
|
451
|
+
put ' put ",""SYSJOBID"" : ""&sysjobid"" "; ';
|
|
452
|
+
put ' put ",""SYSSCPL"" : ""&sysscpl"" "; ';
|
|
453
|
+
put ' put ",""SYSSITE"" : ""&syssite"" "; ';
|
|
454
|
+
put ' put ",""SYSTCPIPHOSTNAME"" : ""&SYSTCPIPHOSTNAME"" "; ';
|
|
455
|
+
put ' sysvlong=quote(trim(symget(''sysvlong''))); ';
|
|
456
|
+
put ' put '',"SYSVLONG" : '' sysvlong; ';
|
|
457
|
+
put ' syswarningtext=quote(cats(symget(''SYSWARNINGTEXT''))); ';
|
|
458
|
+
put ' put '',"SYSWARNINGTEXT" : '' syswarningtext; ';
|
|
459
|
+
put ' put '',"END_DTTM" : "'' "%sysfunc(datetime(),E8601DT26.6)" ''" ''; ';
|
|
460
|
+
put ' length autoexec $512; ';
|
|
461
|
+
put ' autoexec=quote(urlencode(trim(getoption(''autoexec'')))); ';
|
|
462
|
+
put ' put '',"AUTOEXEC" : '' autoexec; ';
|
|
463
|
+
put ' length memsize $32; ';
|
|
464
|
+
put ' memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)"; ';
|
|
465
|
+
put ' memsize=quote(cats(memsize)); ';
|
|
466
|
+
put ' put '',"MEMSIZE" : '' memsize; ';
|
|
467
|
+
put ' put "}" @; ';
|
|
468
|
+
put ' run; ';
|
|
469
|
+
put '%end; ';
|
|
470
|
+
put ' ';
|
|
471
|
+
put '%mend ms_webout; ';
|
|
472
|
+
put ' ';
|
|
473
|
+
put '%macro mfs_httpheader(header_name ';
|
|
474
|
+
put ' ,header_value ';
|
|
475
|
+
put ')/*/STORE SOURCE*/; ';
|
|
476
|
+
put '%global sasjs_stpsrv_header_loc; ';
|
|
477
|
+
put '%local fref fid i; ';
|
|
478
|
+
put ' ';
|
|
479
|
+
put '%if %sysfunc(filename(fref,&sasjs_stpsrv_header_loc)) ne 0 %then %do; ';
|
|
480
|
+
put ' %put &=fref &=sasjs_stpsrv_header_loc; ';
|
|
481
|
+
put ' %put %str(ERR)OR: %sysfunc(sysmsg()); ';
|
|
482
|
+
put ' %return; ';
|
|
483
|
+
put '%end; ';
|
|
484
|
+
put ' ';
|
|
485
|
+
put '%let fid=%sysfunc(fopen(&fref,A)); ';
|
|
486
|
+
put ' ';
|
|
487
|
+
put '%if &fid=0 %then %do; ';
|
|
488
|
+
put ' %put %str(ERR)OR: %sysfunc(sysmsg()); ';
|
|
489
|
+
put ' %return; ';
|
|
490
|
+
put '%end; ';
|
|
491
|
+
put ' ';
|
|
492
|
+
put '%let rc=%sysfunc(fput(&fid,%str(&header_name): %str(&header_value))); ';
|
|
493
|
+
put '%let rc=%sysfunc(fwrite(&fid)); ';
|
|
494
|
+
put ' ';
|
|
495
|
+
put '%let rc=%sysfunc(fclose(&fid)); ';
|
|
496
|
+
put '%let rc=%sysfunc(filename(&fref)); ';
|
|
497
|
+
put ' ';
|
|
498
|
+
put '%mend mfs_httpheader; ';
|
|
499
|
+
/* WEBOUT END */
|
|
500
|
+
put '%macro webout(action,ds,dslabel=,fmt=,missing=NULL,showmeta=NO);';
|
|
501
|
+
put ' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing';
|
|
502
|
+
put ' ,showmeta=&showmeta';
|
|
503
|
+
put ' )';
|
|
504
|
+
put '%mend;';
|
|
505
|
+
run;
|
|
506
|
+
|
|
507
|
+
/* add precode and code */
|
|
508
|
+
%local x fref freflist;
|
|
509
|
+
%let freflist=&precode &code ;
|
|
510
|
+
%do x=1 %to %sysfunc(countw(&freflist));
|
|
511
|
+
%let fref=%scan(&freflist,&x);
|
|
512
|
+
%put &sysmacroname: adding &fref;
|
|
513
|
+
data _null_;
|
|
514
|
+
file &sasjsref lrecl=3000 termstr=crlf mod;
|
|
515
|
+
infile &fref lrecl=3000;
|
|
516
|
+
input;
|
|
517
|
+
put _infile_;
|
|
518
|
+
run;
|
|
519
|
+
%end;
|
|
520
|
+
|
|
521
|
+
/* create the web service */
|
|
522
|
+
%ms_createfile(&path/&name..sas, inref=&sasjsref, mdebug=&mdebug)
|
|
523
|
+
|
|
524
|
+
%put ;%put ;%put ;%put ;%put ;%put ;
|
|
525
|
+
%put &sysmacroname: STP &name successfully created in &path;
|
|
526
|
+
%put ;%put ;%put ;
|
|
527
|
+
%put Check it out here:;
|
|
528
|
+
%put ;%put ;%put ;
|
|
529
|
+
%put &_sasjs_apiserverurl.&_sasjs_apipath?_PROGRAM=&path/&name;
|
|
530
|
+
%put ;%put ;%put ;%put ;%put ;%put ;
|
|
531
|
+
|
|
532
|
+
%mend ms_createwebservice;
|