From 456d10a90e6b44517420fa0d777407e37cff3679 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Wed, 7 Apr 2021 22:28:42 +0000 Subject: [PATCH 1/2] fix: switching to data step for JSON generation in mp_jsonout and the sasjs/adapter for improved reliability when data contains special characters. Closes #12 --- base/mp_jsonout.sas | 23 ++++++++++++++--------- viya/mv_webout.sas | 6 +++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/base/mp_jsonout.sas b/base/mp_jsonout.sas index 1ac804d..3b12e85 100644 --- a/base/mp_jsonout.sas +++ b/base/mp_jsonout.sas @@ -4,8 +4,11 @@ @details PROC JSON is faster but will produce errs like the ones below if special chars are encountered. - >An object or array close is not valid at this point in the JSON text. - >Date value out of range + > ERROR: Some code points did not transcode. + + > An object or array close is not valid at this point in the JSON text. + + > Date value out of range If this happens, try running with ENGINE=DATASTEP. @@ -14,7 +17,9 @@ filename tmp temp; data class; set sashelp.class;run; + %mp_jsonout(OPEN,jref=tmp) %mp_jsonout(OBJ,class,jref=tmp) + %mp_jsonout(CLOSE,jref=tmp) data _null_; infile tmp; @@ -27,18 +32,18 @@ For more information see https://sasjs.io @param action Valid values: - * OPEN - opens the JSON - * OBJ - sends a table with each row as an object - * ARR - sends a table with each row in an array - * CLOSE - closes the JSON + @li OPEN - opens the JSON + @li OBJ - sends a table with each row as an object + @li ARR - sends a table with each row in an array + @li CLOSE - closes the JSON @param ds the dataset to send. Must be a work table. @param jref= the fileref to which to send the JSON @param dslabel= the name to give the table in the exported JSON @param fmt= Whether to keep or strip formats from the table - @param engine= Which engine to use to send the JSON, options are: - * PROCJSON (default) - * DATASTEP + @param engine= Which engine to use to send the JSON, valid options are: + @li PROCJSON (default) + @li DATASTEP (more reliable when data has non standard characters) @param dbg= DEPRECATED - was used to conditionally add PRETTY to proc json but this can cause line truncation in large files. diff --git a/viya/mv_webout.sas b/viya/mv_webout.sas index 44f965b..6b3f77b 100644 --- a/viya/mv_webout.sas +++ b/viya/mv_webout.sas @@ -1,5 +1,5 @@ /** - @file mv_webout.sas + @file @brief Send data to/from the SAS Viya Job Execution Service @details This macro should be added to the start of each Job Execution Service, **immediately** followed by a call to: @@ -11,7 +11,7 @@ following syntax: data some datasets; * make some data ; - retain some columns; + retain some columns; run; %mv_webout(OPEN) @@ -162,7 +162,7 @@ %end; %else %if &action=ARR or &action=OBJ %then %do; %mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt - ,jref=&fref,engine=PROCJSON,dbg=%str(&_debug) + ,jref=&fref,engine=DATASTEP,dbg=%str(&_debug) ) %end; %else %if &action=CLOSE %then %do; From 18be74a1c28e98deb09ba846571b871f8cf5eca0 Mon Sep 17 00:00:00 2001 From: rafgag <69139928+rafgag@users.noreply.github.com> Date: Thu, 8 Apr 2021 09:03:05 +0200 Subject: [PATCH 2/2] Update mp_jsonout.sas mod option added to the file statement in the last %else %if statement (&action=CLOSE) to avoid output file being overwritten --- base/mp_jsonout.sas | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/mp_jsonout.sas b/base/mp_jsonout.sas index 3b12e85..403cea8 100644 --- a/base/mp_jsonout.sas +++ b/base/mp_jsonout.sas @@ -165,8 +165,8 @@ %end; %else %if &action=CLOSE %then %do; - data _null_;file &jref encoding='utf-8'; + data _null_;file &jref encoding='utf-8' mod; put "}"; run; %end; -%mend; \ No newline at end of file +%mend;