This program performs a series of unit tests: 1. Simulation of an incoming web request (FETCH) via macro variables and verification of the resulting table via `mp_assertdsobs`. 2. Generation of a complex JSON stream (Arrays and Objects) to a temporary physical file via `mv_webout`. 3. Rereading of the generated JSON file using the `LIBNAME JSON` engine to validate the integrity and structure of the produced data.
Data Analysis
Type : CREATION_INTERNE
All data is simulated within the script (DATA step, macro variables) or generated by the tested macros.
1 Code Block
DATA STEP
Explanation : Test environment initialization: definition of macro variables simulating data received from a web request (SASjs format).
Copied!
data _null_;
call symputx('sasjs1data','area:$char4.'!!'0d0a'x!!'Adak');
call symputx('sasjs_tables','areas');
run;
%put &=sasjs1data;
Explanation : JSON output generation test: creation of dummy data and writing to a temporary file via the OPEN, ARR (Array), OBJ (Object) and CLOSE commands of mv_webout.
Copied!
%let fref=%mf_getuniquefileref();
%global _metaperson;
data some datasets;
x=1;
run;
%mv_webout(OPEN,fref=&fref,stream=N)
%mv_webout(ARR,some,fref=&fref,stream=N)
%mv_webout(OBJ,datasets,fref=&fref,stream=N)
%mv_webout(CLOSE,fref=&fref,stream=N)
1
%let fref=%mf_getuniquefileref();
2
%global _metaperson;
3
DATA some datasets;
4
x=1;
5
RUN;
6
%mv_webout(OPEN,fref=&fref,stream=N)
7
%mv_webout(ARR,some,fref=&fref,stream=N)
8
%mv_webout(OBJ,datasets,fref=&fref,stream=N)
9
%mv_webout(CLOSE,fref=&fref,stream=N)
4 Code Block
DATA STEP
Explanation : Validation of the produced JSON file: display of raw content in the log, parsing via the LIBNAME JSON engine, and final assertion to compare retrieved values.
Copied!
data _null_;
infile &fref;
input;
putlog _infile_;
run;
libname test JSON (&fref);
data root;
set test.root;
call symputx('checkval',sysvlong);
run;
data alldata;
set test.alldata;
run;
%mp_assert(
iftrue=(%str(&checkval)=%str(&sysvlong)),
desc=Check if the sysvlong value was created
)
1
DATA _null_;
2
INFILE &fref;
3
INPUT;
4
putlog _infile_;
5
RUN;
6
7
LIBNAME test JSON (&fref);
8
DATA root;
9
SET test.root;
10
call symputx('checkval',sysvlong);
11
RUN;
12
DATA alldata;
13
SET test.alldata;
14
RUN;
15
16
%mp_assert(
17
iftrue=(%str(&checkval)=%str(&sysvlong)),
18
desc=Check IF the sysvlong value was created
19
)
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.