The data used for testing ('work.somedata1' and 'work.somedata2') is created directly within the script using a DATA step. No external data source is required.
1 Code Block
DATA STEP
Explanation : This DATA _NULL_ block writes the SAS code that will form the body of the web service. It uses '%webout' to prepare web output. An internal macro '%x' is defined to iterate over a list of tables (coming from 'sasjs_tables' or uploaded files) and write them as objects to the web response, converting missing values to character strings.
Explanation : Call to the '%ms_createwebservice' macro to create and deploy the 'sendObj' web service in the directory specified by '&mcTestAppLoc/services', using the code generated in the previous step.
Copied!
%put creating web service: &mcTestAppLoc/services;
%ms_createwebservice(
path=&mcTestAppLoc/services,
name=sendObj,
mdebug=&sasjs_mdebug
)
%put created web service: &mcTestAppLoc/services;
1
%put creating web service: &mcTestAppLoc/services;
2
%ms_createwebservice(
3
path=&mcTestAppLoc/services,
4
name=sendObj,
5
mdebug=&sasjs_mdebug
6
)
7
%put created web service: &mcTestAppLoc/services;
3 Code Block
Macro Call
Explanation : Call to the '%mp_assert' macro to verify that the service creation occurred without errors (condition 'syscc=0'). The test result is recorded in 'work.test_results'.
Copied!
%mp_assert(
iftrue=(&syscc=0),
desc=No errors after service creation,
outds=work.test_results
)
1
%mp_assert(
2
iftrue=(&syscc=0),
3
desc=No errors after service creation,
4
outds=work.test_results
5
)
4 Code Block
DATA STEP Data
Explanation : This DATA step creates two test SAS tables, 'work.somedata1' and 'work.somedata2', with identical data containing numeric values, a string with quotes and spaces, and a special missing value.
Explanation : Call to the '%ms_testservice' macro to execute the 'sendObj' web service. Tables 'work.somedata1' and 'work.somedata2' are passed as input. The service results will be stored in the 'testlib1' library.
Explanation : These two DATA _NULL_ steps verify the content of the tables returned by the web service ('testlib1.somedata1' and 'testlib1.somedata2'). If the data conforms to expectations (notably the transformation of the missing value '.z' to character 'Z'), the macro variables 'test1' and 'test2' are set to 'PASS'.
Copied!
%let test1=FAIL;
data _null_;
set testlib1.somedata1;
if x=1 and y=' t"w"o' and z="Z" then call symputx('test1','PASS');
putlog (_all_)(=);
run;
%let test2=FAIL;
data _null_;
set testlib1.somedata2;
if x=1 and y=' t"w"o' and z="Z" then call symputx('test2','PASS');
putlog (_all_)(=);
run;
1
%let test1=FAIL;
2
DATA _null_;
3
SET testlib1.somedata1;
4
IF x=1 and y=' t"w"o' and z="Z"THEN call symputx('test1','PASS');
5
putlog (_all_)(=);
6
RUN;
7
8
%let test2=FAIL;
9
DATA _null_;
10
SET testlib1.somedata2;
11
IF x=1 and y=' t"w"o' and z="Z"THEN call symputx('test2','PASS');
12
putlog (_all_)(=);
13
RUN;
7 Code Block
Macro Call
Explanation : Final calls to the '%mp_assert' macro to formally validate the results of the previous verifications. If the macro variables 'test1' and 'test2' are 'PASS', the tests are considered successful.
Copied!
%mp_assert(
iftrue=(&test1=PASS),
desc=somedata1 created correctly,
outds=work.test_results
)
%mp_assert(
iftrue=(&test2=PASS),
desc=somedata2 created correctly,
outds=work.test_results
)
1
%mp_assert(
2
iftrue=(&test1=PASS),
3
desc=somedata1 created correctly,
4
outds=work.test_results
5
)
6
%mp_assert(
7
iftrue=(&test2=PASS),
8
desc=somedata2 created correctly,
9
outds=work.test_results
10
)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright information (HMS Analytical Software GmbH, SAS Institute Inc.) is detected in comments referring to other files.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.