The script creates a dataset containing a series of numerical values, including special missing values (._, .a, .b, etc.). It uses the mp_jsonout macro to export this data to JSON. The resulting file is then re-read and converted (special values being treated as text in the JSON) to verify that the reconstructed data exactly matches the original data via PROC COMPARE.
Data Analysis
Type : CREATION_INTERNE
The 'demo' table is generated locally via an iterative Data Step.
1 Code Block
DATA STEP Data
Explanation : Definition of a temporary file and creation of the 'demo' data table containing various numerical values and special missing values for testing.
Copied!
filename webref temp;
data demo;
do x=._,.,.a,.b,.c,.d,.e,-99, 0, 1,2, 3.333333;
output;
end;
run;
1
filename webref temp;
2
3
DATA demo;
4
DO x=._,.,.a,.b,.c,.d,.e,-99, 0, 1,2, 3.333333;
5
OUTPUT;
6
END;
7
RUN;
2 Code Block
MACRO CALL
Explanation : Call to the mp_jsonout macro to export the 'demo' table to the temporary file 'webref', with the missing=STRING option to handle specific formats.
Explanation : Debugging step displaying the raw content of the generated JSON file in the SAS log.
Copied!
data _null_;
infile webref;
input;
putlog _infile_;
run;
1
DATA _null_;
2
INFILE webref;
3
INPUT;
4
putlog _infile_;
5
RUN;
4 Code Block
DATA STEP Data
Explanation : Reading the JSON file via the LIBNAME JSON engine and reconstructing the 'test' table. Includes logic to convert character strings (representing special missing values) back into SAS numerical format.
Copied!
libname web JSON fileref=webref;
data work.test(keep=x);
set web.demo(rename=(x=y));
if y ='_' then x=._;
else if anyalpha(y) then x=input(cats(".",y),best.);
else x=input(y,best.);
put (_all_)(=);
run;
1
LIBNAME web JSON fileref=webref;
2
3
DATA work.test(keep=x);
4
SET web.demo(rename=(x=y));
5
IF y ='_'THEN x=._;
6
ELSEIF anyalpha(y) THEN x=INPUT(cats(".",y),best.);
7
ELSE x=INPUT(y,best.);
8
put (_all_)(=);
9
RUN;
5 Code Block
MACRO CALL
Explanation : Verification that no system error (SYSCC) has occurred so far.
Copied!
%mp_assert(
iftrue=(&syscc=0),
desc=Checking for error condition with special missing export,
outds=work.test_results
)
1
%mp_assert(
2
iftrue=(&syscc=0),
3
desc=Checking for error condition with special missing export,
4
outds=work.test_results
5
)
6 Code Block
PROC COMPARE
Explanation : Structural and content comparison between the original 'demo' table and the table generated from the JSON 'test'.
Explanation : Final assertion verifying that PROC COMPARE detected no differences (SYSINFO=0).
Copied!
%mp_assert(
iftrue=(&sysinfo=0),
desc=Returned json is identical to input table for all special missings,
outds=work.test_results
)
1
%mp_assert(
2
iftrue=(&sysinfo=0),
3
desc=Returned json is identical to INPUTTABLE for all special missings,
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.