Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
ms_testservice.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Will execute a SASjs web service on SASjs Server
4 @details Prepares the input files and retrieves the resulting datasets from
5 the response JSON.
6
7 @param [in] program The Stored Program endpoint to test
8 @param [in] inputfiles=(0) A list of space seperated fileref:filename pairs as
9 follows:
10 inputfiles=inref:filename inref2:filename2
11 @param [in] inputdatasets= (0) All datasets in this space seperated list are
12 converted into SASJS-formatted CSVs (see mp_ds2csv.sas) files and added to
13 the list of `inputfiles` for ingestion. The dataset will be sent with the
14 same name (no need for a colon modifier).
15 @param [in] inputparams=(0) A dataset containing name/value pairs in the
16 following format:
17 |name:$32|value:$1000|
18 |---|---|
19 |stpmacname|some value|
20 |mustbevalidname|can be anything, oops, %abort!!|
21
22 @param [in] debug= (131) The _debug value to send to the STP. The response
23 log is returned when the value is 131 or above, which outlogds depends on.
24 @param [in] mdebug= (0) Set to 1 to provide macro debugging (this macro)
25 @param [out] outlib= (0) Output libref to contain the final tables. Set to
26 0 if the service output is not in JSON format.
27 @param [out] outref= (0) Output fileref to create, to contain the full _webout
28 response.
29 @param [out] outlogds= (_null_) Set to the name of a dataset to contain the
30 log. Table format:
31 |line:$2000|
32 |---|
33 |log line 1|
34 |log line 2|
35
36 <h4> SAS Macros </h4>
37 @li mf_getuniquefileref.sas
38 @li mf_getuniquename.sas
39 @li mp_chop.sas
40 @li mp_ds2csv.sas
41 @li ms_runstp.sas
42
43 <h4> Related Programs </h4>
44 @li mx_execute.sas
45
46 @version 9.4
47 @author Allan Bowe
48
49**/
50
51%macro ms_testservice(program,
52 inputfiles=0,
53 inputdatasets=0,
54 inputparams=0,
55 debug=131,
56 mdebug=0,
57 outlib=0,
58 outref=0,
59 outlogds=_null_
60)/*/STORE SOURCE*/;
61%local dbg i var ds1 fref1 chopout1 chopout2;
62%if &mdebug=1 %then %do;
63 %put &sysmacroname entry vars:;
64 %put _local_;
65%end;
66%else %let dbg=*;
67
68/* convert inputdatasets to filerefs */
69%if "&inputdatasets" ne "0" %then %do;
70 %if %quote(&inputfiles)=0 %then %let inputfiles=;
71 %do i=1 %to %sysfunc(countw(&inputdatasets,%str( )));
72 %let var=%scan(&inputdatasets,&i,%str( ));
73 %local dsref&i;
74 %let dsref&i=%mf_getuniquefileref();
75 %mp_ds2csv(&var,outref=&&dsref&i,headerformat=SASJS)
76 %let inputfiles=&inputfiles &&dsref&i:%scan(&var,-1,.);
77 %end;
78%end;
79
80/* parse the filerefs - convert to a dataset */
81%let ds1=%mf_getuniquename();
82data &ds1;
83 length fileref $8 name $32 filename $256 var $300;
84 if "&inputfiles" ne "0" then do;
85 webcount=countw("&inputfiles");
86 do i=1 to webcount;
87 var=scan("&inputfiles",i,' ');
88 fileref=scan(var,1,':');
89 name=scan(var,2,':');
90 filename=cats(name,'.csv');
91 output;
92 end;
93 end;
94run;
95
96
97/* execute the STP. _debug is forwarded to ms_runstp, whose own default is
98 131 - the log separator this macro chops on is only present when the
99 server runs in debug mode, so outlogds needs the default. */
100%let fref1=%mf_getuniquefileref();
101
102%ms_runstp(&program
103 ,debug=&debug
104 ,inputparams=&inputparams
105 ,inputfiles=&ds1
106 ,outref=&fref1
107 ,mdebug=&mdebug
108 ,outlogds=&outlogds
109)
110
111
112/* chop out JSON section */
113%local matchstr chopout;
114%let matchstr=SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784;
115%let chopout=%sysfunc(pathname(work))/%mf_getuniquename(prefix=chop);
116
117%mp_chop("%sysfunc(pathname(&fref1,F))"
118 ,matchvar=matchstr
119 ,keep=FIRST
120 ,matchpoint=START
121 ,offset=-1
122 ,outfile="&chopout"
123 ,mdebug=&mdebug
124)
125
126%if &outlib ne 0 %then %do;
127 libname &outlib json "&chopout";
128%end;
129%if &outref ne 0 %then %do;
130 filename &outref "&chopout";
131%end;
132
133%if &mdebug=0 %then %do;
134 filename &webref clear;
135 filename &fref1 clear;
136%end;
137%else %do;
138 %put &sysmacroname exit vars:;
139 %put _local_;
140%end;
141
142%mend ms_testservice;