Attention : This code requires administrator privileges.
The script begins by dynamically defining the code for a web service that reads `sashelp.class` and uses `%webout` functions to produce a JSON result. This code is then deployed as a web service named 'testsvc' via the `%mv_createwebservice` macro. A jobflow is initiated with `%mv_jobflow` to execute this service, with concurrency management and log output. After execution, the service result URI is extracted from the jobflow metadata. The `%mv_getjobresult` macro is used to retrieve the actual service data via this URI. Finally, the script validates that the retrieved data matches the expected content of `sashelp.class` by asserting the number of observations in the resulting dataset, using the `%mp_assertdsobs` macro.
Data Analysis
Type : MIXTE
The primary data source is the internal SAS dataset `sashelp.class`. The script also creates several temporary work datasets (`work.inputjobs`, `work.results`, `myweblib.test`, `work.out`, `work.test_results`) and manipulates temporary filerefs (`testref`, `myjoblog`, `myweb`) for intermediate storage of the service code, jobflow logs, and web service results.
1 Code Block
DATA STEP Data
Explanation : This block uses a `DATA _NULL_` to write SAS code into a temporary file (`testref`). The written code defines a simple `DATA STEP` that loads `sashelp.class` into a dataset named `test`, then uses the `%webout` macros to format this dataset as web output (likely JSON), which is typical for REST services.
Copied!
filename testref temp;
data _null_;
file testref;
put 'data test; set sashelp.class;run;';
put '%webout(OPEN)';
put '%webout(OBJ,test)';
put '%webout(CLOSE)';
run;
1
filename testref temp;
2
DATA _null_;
3
file testref;
4
put 'data test; set sashelp.class;run;';
5
put '%webout(OPEN)';
6
put '%webout(OBJ,test)';
7
put '%webout(CLOSE)';
8
RUN;
2 Code Block
MACRO mv_createwebservice
Explanation : Calls the `%mv_createwebservice` macro to create and deploy a web service named `testsvc`. The deployment path is specified by `&mcTestAppLoc/services/temp`, and the service code is read from the previously defined temporary fileref `testref`.
Explanation : This block prepares the web service execution. A `work.inputjobs` dataset is created to specify the program (`testsvc`) to be executed. Then, the `%mv_jobflow` macro is called to launch the service execution, managing concurrency with `maxconcurrency=4`. Jobflow results are stored in `work.results` and the execution log is saved in the `myjoblog` fileref.
Copied!
data work.inputjobs;
_program="&mcTestAppLoc/services/temp/testsvc";
run;
%mv_jobflow(inds=work.inputjobs
,maxconcurrency=4
,outds=work.results
,outref=myjoblog
)
1
DATA work.inputjobs;
2
_program="&mcTestAppLoc/services/temp/testsvc";
3
RUN;
4
%mv_jobflow(inds=work.inputjobs
5
,maxconcurrency=4
6
,outds=work.results
7
,outref=myjoblog
8
)
4 Code Block
DATA STEP
Explanation : Reads the content of the `myjoblog` file generated by the jobflow and writes it directly to the SAS log, allowing visualization of service execution messages.
Copied!
data _null_;
infile myjoblog;
input;
put _infile_;
run;
1
DATA _null_;
2
INFILE myjoblog;
3
INPUT;
4
put _infile_;
5
RUN;
5 Code Block
DATA STEP
Explanation : This `DATA _NULL_` iterates through the `work.results` dataset (which contains jobflow metadata) and extracts the value of the `uri` variable to store it in a global macro variable named `uri`, essential for retrieving service results. All variables are also displayed in the log.
Copied!
data _null_;
set work.results;
call symputx('uri',uri);
put (_all_)(=);
run;
1
DATA _null_;
2
SET work.results;
3
call symputx('uri',uri);
4
put (_all_)(=);
5
RUN;
6 Code Block
MACRO mv_getjobresult Data
Explanation : Calls the `%mv_getjobresult` macro to retrieve web service results using the previously obtained URI. The `result=WEBOUT_JSON` parameter indicates that the expected output is in JSON format, which is stored in the `myweb` fileref and a `test` dataset within the `myweblib` library.
Explanation : Reads the raw content of the `myweb` file (the JSON result of the web service) and displays it in the SAS log for direct examination.
Copied!
data _null_;
infile myweb;
input;
putlog _infile_;
run;
1
DATA _null_;
2
INFILE myweb;
3
INPUT;
4
putlog _infile_;
5
RUN;
8 Code Block
DATA STEP Data
Explanation : Creates a work dataset named `work.out` by reading the structured data from the `myweblib.test` dataset, which contains `sashelp.class` data as returned by the web service and interpreted by the `mv_getjobresult` macro. Also displays all variables of the new dataset in the log.
Copied!
data work.out;
set myweblib.test;
put (_all_)(=);
run;
1
DATA work.out;
2
SET myweblib.test;
3
put (_all_)(=);
4
RUN;
9 Code Block
MACRO mp_assertdsobs Data
Explanation : Calls the `%mp_assertdsobs` test macro to verify that the `work.out` dataset contains exactly 19 observations. This validates that the web service has correctly returned all rows from `sashelp.class`. The result of this assertion is recorded in the `work.test_results` dataset.
Copied!
%mp_assertdsobs(work.out,
desc=Test1 - 19 obs from sashelp.class in service result,
test=EQUALS 19,
outds=work.test_results
)
1
%mp_assertdsobs(work.out,
2
desc=Test1 - 19 obs from sashelp.class in service RESULT,
3
test=EQUALS 19,
4
outds=work.test_results
5
)
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.
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.