<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Parsing Json Array stored in SAS Column [SAS DI] in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/700922#M214563</link>
    <description>&lt;P&gt;Greetings everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am facing the following issue: I have loaded a dataset in SASDI that some columns contain json arrays.&lt;/P&gt;&lt;P&gt;The problem with json arrays is that do not have always the same length. At first I used the technique provided by the below thread&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/SAS-DI-4-9-JSON-Column-Parse-Data-Step/m-p/684905#M207646" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/SAS-DI-4-9-JSON-Column-Parse-Data-Step/m-p/684905#M207646&lt;/A&gt;&lt;/P&gt;&lt;P&gt;by ChrisZ and it works fine with one size arrays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When it comes to arrays that have size greater than one, the code reads only the first line.&lt;/P&gt;&lt;P&gt;The expected outcome is to generate in the below example lines that are associated with the number of the array elements.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;content&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;[{"item":"value1"}, {"item":"value2"},{"item":"value3"}]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;value1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;value2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;value3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I searched for the following:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;SCANOVER function: this comes in handy but I think that it can be used only in the infile statement&lt;/LI&gt;&lt;LI&gt;I tried the PROC DS2 with no luck: I was able to execute the code but when the parser is initialized; it does not see any of the tokens provided in the json column&lt;/LI&gt;&lt;LI&gt;JSON lib does not supported by the version of our SAS system&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Below you will find the attempt with the PROC DS2 &amp;amp; the sas version&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS_Enterprise_Guide_Version.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51936i726327002401CD7D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAS_Enterprise_Guide_Version.PNG" alt="SAS_Enterprise_Guide_Version.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Contents of HAVE Dataset&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_id&lt;/TD&gt;&lt;TD&gt;contactProgress&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5fa1b999c2dc2170299dc0b4&lt;/TD&gt;&lt;TD&gt;[{"date": { "$date": "2020-11-04T15:20:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "020", "description": "No answer"}, "notes": "this is the content of the text provided, "type": "INPROGRESS"}, {"date": { "$date": "2020-11-04T18:00:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "010", "description": "Communication"}, "notes": "This is the new note test", "type": "INPROGRESS"}, {"date": { "$date": "2020-11-05T16:30:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "010", "description": "Communication"}, "notes": "The test quotation has been sent to the client", "type": "INPROGRESS"}]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
SET WORK.QUERY_FOR_WRK_LEADS_KPIS;
RUN;

PROC DS2;
DATA WANT (OVERWRITE=YES);
DCL PACKAGE JSON J();
DCL INTEGER TOKENTYPE PARSEFLAGS;
DCL NVARCHAR(128) TOKEN;
DCL INTEGER RC;
DCL CHAR(2000) CHARACTER SET UTF8 CONTACT_PROGRESS;

METHOD INIT();
RC = J.CREATEPARSER( CONTACT_PROGRESS, 32767 );

DO WHILE( RC = 0 );
J.GETNEXTTOKEN( RC, TOKEN, TOKENTYPE, PARSEFLAGS );
IF (TOKEN = '') THEN do; 
%put 'Empty Token Found';

end;
END;
END;

METHOD RUN();
SET WORK.HAVE;
END;


method term();
rc = j.destroyParser();
end;

ENDDATA;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Nov 2020 14:50:19 GMT</pubDate>
    <dc:creator>vfarmak</dc:creator>
    <dc:date>2020-11-23T14:50:19Z</dc:date>
    <item>
      <title>Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/700922#M214563</link>
      <description>&lt;P&gt;Greetings everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am facing the following issue: I have loaded a dataset in SASDI that some columns contain json arrays.&lt;/P&gt;&lt;P&gt;The problem with json arrays is that do not have always the same length. At first I used the technique provided by the below thread&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/SAS-DI-4-9-JSON-Column-Parse-Data-Step/m-p/684905#M207646" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/SAS-DI-4-9-JSON-Column-Parse-Data-Step/m-p/684905#M207646&lt;/A&gt;&lt;/P&gt;&lt;P&gt;by ChrisZ and it works fine with one size arrays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When it comes to arrays that have size greater than one, the code reads only the first line.&lt;/P&gt;&lt;P&gt;The expected outcome is to generate in the below example lines that are associated with the number of the array elements.&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;content&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;[{"item":"value1"}, {"item":"value2"},{"item":"value3"}]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;value1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;value2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;000001&lt;/TD&gt;&lt;TD&gt;value3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I searched for the following:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;SCANOVER function: this comes in handy but I think that it can be used only in the infile statement&lt;/LI&gt;&lt;LI&gt;I tried the PROC DS2 with no luck: I was able to execute the code but when the parser is initialized; it does not see any of the tokens provided in the json column&lt;/LI&gt;&lt;LI&gt;JSON lib does not supported by the version of our SAS system&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Below you will find the attempt with the PROC DS2 &amp;amp; the sas version&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS_Enterprise_Guide_Version.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51936i726327002401CD7D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SAS_Enterprise_Guide_Version.PNG" alt="SAS_Enterprise_Guide_Version.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Contents of HAVE Dataset&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_id&lt;/TD&gt;&lt;TD&gt;contactProgress&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5fa1b999c2dc2170299dc0b4&lt;/TD&gt;&lt;TD&gt;[{"date": { "$date": "2020-11-04T15:20:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "020", "description": "No answer"}, "notes": "this is the content of the text provided, "type": "INPROGRESS"}, {"date": { "$date": "2020-11-04T18:00:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "010", "description": "Communication"}, "notes": "This is the new note test", "type": "INPROGRESS"}, {"date": { "$date": "2020-11-05T16:30:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "010", "description": "Communication"}, "notes": "The test quotation has been sent to the client", "type": "INPROGRESS"}]&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA HAVE;
SET WORK.QUERY_FOR_WRK_LEADS_KPIS;
RUN;

PROC DS2;
DATA WANT (OVERWRITE=YES);
DCL PACKAGE JSON J();
DCL INTEGER TOKENTYPE PARSEFLAGS;
DCL NVARCHAR(128) TOKEN;
DCL INTEGER RC;
DCL CHAR(2000) CHARACTER SET UTF8 CONTACT_PROGRESS;

METHOD INIT();
RC = J.CREATEPARSER( CONTACT_PROGRESS, 32767 );

DO WHILE( RC = 0 );
J.GETNEXTTOKEN( RC, TOKEN, TOKENTYPE, PARSEFLAGS );
IF (TOKEN = '') THEN do; 
%put 'Empty Token Found';

end;
END;
END;

METHOD RUN();
SET WORK.HAVE;
END;


method term();
rc = j.destroyParser();
end;

ENDDATA;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 14:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/700922#M214563</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-11-23T14:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/700926#M214565</link>
      <description>&lt;P&gt;Why do you have that macro code in the middle of your PROC DS2 step?&amp;nbsp; The %PUT is always going to print its message while SAS is scanning the code and preparing the PROC step to execute.&amp;nbsp; The %PUT will not do anything while the step is running.&amp;nbsp; Did you mean to use a normal PUT statement there?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 15:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/700926#M214565</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-23T15:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/700931#M214570</link>
      <description>&lt;P&gt;I used it for debugging purposes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed it as you suggested, but nothing is printed.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 15:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/700931#M214570</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-11-23T15:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701213#M214701</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp; wrote a blog about it reading JSONL before.&lt;/P&gt;
&lt;P&gt;Or could write some raw sas data step code to parse it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 13:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701213#M214701</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-24T13:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701243#M214715</link>
      <description>&lt;P&gt;Yes indeed I am aware of it.&lt;/P&gt;&lt;P&gt;However it focuses on Json data retrieved from a web service, rather than processing json arrays stored in a sas column.&lt;/P&gt;&lt;P&gt;I used an excerpt from the PROC DS2 that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;with no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem resides in how to target the column's value. He uses RestAPI to capture the data and not a sas dataset with json values stored.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 15:10:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701243#M214715</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-11-24T15:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701296#M214734</link>
      <description>&lt;P&gt;I think your best option is to use the JSON libname engine. However, this operates only on text files, so you first need to extract the JSON data from the data set and create a text file for each record, or one large JSON text file with a wrapper object.&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;This assumes the data field you're reading is a valid complete JSON string.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's illustrate using an example. I don't have your data, so I'll simulate by creating a similar data set from SASHELP.CLASS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datasource = sashelp.class;

/* Create a new subfolder in WORK to hold */
/* temp JSON files, avoiding conflicts    */
options dlcreatedir;
%let workpath = %sysfunc(getoption(WORK))/json;
libname json "&amp;amp;workpath.";
libname json clear;

/* Will create a run a separate PROC JSON step */
/* for each record.  This might take a while   */
/* for very large data.                        */
/* Each iteration will create a new JSON file  */
data _null_;
 set &amp;amp;datasource.;
 call execute(catt('filename out "',"&amp;amp;workpath./out",_n_,'.json";'));
 call execute('proc json out=out nosastags ;');
 call execute("export &amp;amp;datasource.(obs="||_n_||" firstobs="||_n_||");");
 call execute('run;');
run;

data records;
 length ID $ 10 Details $ 32767;
 infile "&amp;amp;workpath./out*.json";
 input;
 ID = cats('ID',put(_n_,z3.));
 details = _infile_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This creates a data set that looks similar to yours:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2020-11-24_12-40-14.jpg" style="width: 413px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51970i02C0650271ADC6AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="2020-11-24_12-40-14.jpg" alt="2020-11-24_12-40-14.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now, starting with this, let's create a JSON file that has these records formatted as name/value pairs:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Now create one large JSON file that wraps these name/value pairs */
filename stage TEMP;
data _null_;
 length v $ 15;
 file stage;
 set records end=done;
 if _n_ = 1 then do;
  put '{';
 end;
 v = cats('"',ID,'":');
 put v;
 put Details;
 if done then do;
  put '}';
 end;
 else put ',';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The resulting JSON looks like this:&lt;/P&gt;
&lt;PRE&gt;{
  "ID001": [
    {
      "Name": "Alfred",
      "Sex": "M",
      "Age": 14,
      "Height": 69,
      "Weight": 112.5
    }
  ],
  "ID002": [
    {
      "Name": "John",
      "Sex": "M",
      "Age": 12,
      "Height": 59,
      "Weight": 99.5
    }
  ],
  "ID003": [
    {
      "Name": "Joyce",
      "Sex": "F",
      "Age": 11,
      "Height": 51.3,
      "Weight": 50.5
    }
  ],&lt;/PRE&gt;
&lt;P&gt;Now we can use the JSON libname engine to read this like a set of data sets that we can assemble:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname final json fileref=stage;
data final;
 length ID $ 15;
 set final.ID: indsname=src;
 drop ordinal:;
 ID=scan(src,2,'.');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2020-11-24_12-44-53.jpg" style="width: 339px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51971i7326BCDD85D8E6E9/image-size/large?v=v2&amp;amp;px=999" role="button" title="2020-11-24_12-44-53.jpg" alt="2020-11-24_12-44-53.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 17:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701296#M214734</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2020-11-24T17:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701326#M214750</link>
      <description>&lt;P&gt;Let's generalize a little more.&amp;nbsp; First let's take the two example strings posted in the original question and make a dataset out of them.&amp;nbsp; (Note the second string was not valid JSON as one of the quoted strings was missing the close quote so I fixed that).&amp;nbsp;&amp;nbsp;So we have two variables&amp;nbsp; ID and a JSON string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards truncover ;
  input id :$10. json $1000. ;
cards4;
001 [{"item":"value1"}, {"item":"value2"},{"item":"value3"}]
002 [{"date": { "$date": "2020-11-04T15:20:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "020", "description": "No answer"}, "notes": "this is the content of the text provided", "type": "INPROGRESS"}, {"date": { "$date": "2020-11-04T18:00:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "010", "description": "Communication"}, "notes": "This is the new note test", "type": "INPROGRESS"}, {"date": { "$date": "2020-11-05T16:30:00.000Z" }, "details": {"code": "040", "description": "Follow up"}, "feedback": {"code": "010", "description": "Communication"}, "notes": "The test quotation has been sent to the client", "type": "INPROGRESS"}]
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's use code like Chris' to generate a JSON file.&amp;nbsp; Note the use of the TEMP engine to make get a temporary file.&amp;nbsp; Also I much prefer to place the continuation characters (commas in JSON syntax) at the START of the line instead of the END of the line so that humans can see them easier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename json temp;
data _null_;
  file json;
  set have end=eof;
  if _n_=1 then put '{' @;
  else put ',' @;
  put id :$quote. ':' json ;
  if eof then put '}';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can make a libref using the JSON engine (it will default to look for a FILEREF with the same name as the LIBREF).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname json json ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is what the ALLDATA structure looks like for this JSON data.&lt;/P&gt;
&lt;PRE&gt;     Obs    P    P1     P2          P3             V    Value

       1    1    001                               0
       2    2    001    item                       1    value1
       3    1    001                               0
       4    2    001    item                       1    value2
       5    1    001                               0
       6    2    001    item                       1    value3
       7    1    002                               0
       8    2    002    date                       0
       9    3    002    date        $date          1    2020-11-04T15:20:00.000Z
      10    2    002    details                    0
      11    3    002    details     code           1    040
      12    3    002    details     description    1    Follow up
      13    2    002    feedback                   0
      14    3    002    feedback    code           1    020
      15    3    002    feedback    description    1    No answer
      16    2    002    notes                      1    this is the content of the text provided
      17    2    002    type                       1    INPROGRESS
      18    1    002                               0
      19    2    002    date                       0
      20    3    002    date        $date          1    2020-11-04T18:00:00.000Z
...&lt;/PRE&gt;
&lt;P&gt;P is what level in the JSON hierarchy this value lives at (1,2,3,...)&amp;nbsp; and P1,P2,... are the names of the levels.&amp;nbsp; Note that in this case&amp;nbsp;P1 is the value we wrote from ID and P2 onward of the names in the JSON strings.&amp;nbsp; V tells if VALUE is populated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So we can use this to make a structure that PROC TRANSPOSE can use.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First let's rename P and P1 so that we can then use P: wildcard to find P2,P3,P4,..... without knowing how deep the hierarchy is for this JSON text.&amp;nbsp; As long as those names are short enough we can use them to make variable names.&amp;nbsp; If they are too long we might need to add some more logic to generate unique names.&lt;/P&gt;
&lt;P&gt;To handle the repeating names we can add a sequence number. We can increment the counter whenever P=1. We can use changes in P1 to signal restarting the counter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tall ;
  set json.alldata(rename=(p=first_id p1=id)) ;
  by id notsorted;
  length _name_ $32 _label_ $200 ;
  _label_=catx(' ',of p:);
  _name_ =catx('_',of p:);
  if first.id then seq=0;
  if first_id=1 then seq+1;
  if v=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can use PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data= tall out=want(drop=_name_);
  by id seq notsorted;
  var value;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And get data like this:&lt;/P&gt;
&lt;PRE&gt;                                                           details_     details_      feedback_
Obs    id     seq     item            date__date             code      description      code

 1     001     1     value1
 2     001     2     value2
 3     001     3     value3
 4     002     1               2020-11-04T15:20:00.000Z      040        Follow up        020
 5     002     2               2020-11-04T18:00:00.000Z      040        Follow up        010
 6     002     3               2020-11-05T16:30:00.000Z      040        Follow up        010

         feedback_
Obs     description     notes                                                type

 1
 2
 3
 4     No answer        this is the content of the text provided          INPROGRESS
 5     Communication    This is the new note test                         INPROGRESS
 6     Communication    The test quotation has been sent to the client    INPROGRESS
&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;[See also &lt;A href="https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701296/highlight/true#M214734" target="_self"&gt;the code in this reply that shows how to use DATA step and the JSON libname engine&lt;/A&gt; to read a series of JSON data entries.]&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 15:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701326#M214750</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-12-03T15:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701474#M214819</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;&amp;amp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to run the code but the following error appears:&lt;/P&gt;&lt;PRE&gt;43         libname json json ;
NOTE: JSON data is only read once.  To read the JSON again, reassign the JSON LIBNAME.
ERROR: Invalid JSON in input near line 1 column 5: Encountered an illegal character.
ERROR: Error in the LIBNAME statement.&lt;/PRE&gt;&lt;P&gt;Does this have to do with the version of Enterprise Guide that I am running? Does it support the libname json?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have read&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;blog regarding the json library, I tried to use it with no luck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the main reason that I tried to used the PROC DS2 method.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 10:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701474#M214819</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-11-25T10:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701506#M214823</link>
      <description>&lt;P&gt;So that error is saying the JSON is not well formed. The error is early in the first line, so just look at the file. You can run this data step to dump the first line into the SAS log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  infile json obs=1;
  input;
  list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the JSON is not well formed then reading it with any JSON parser is not going to work.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 12:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701506#M214823</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-25T12:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701520#M214828</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; for you input.&lt;/P&gt;&lt;P&gt;I did used the debug and I have observed the following:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Is it necessary to add the brackets { .. [] ... } in the json file&lt;/LI&gt;&lt;LI&gt;the json variable that is assigned in the filename statement is empty (I suspect that this is the json file written to the temp folder which SAS Enterprise Guide uses to read and write data. Is it true? If so, why I cannot see the value in the debugger?&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Wed, 25 Nov 2020 13:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701520#M214828</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-11-25T13:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701523#M214829</link>
      <description>&lt;P&gt;Also &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt; to give you a better perspective of the debugger I have attached the following screeshot:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="json_sas_datastep.PNG" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51993i8C10B7C2A56BED2A/image-size/large?v=v2&amp;amp;px=999" role="button" title="json_sas_datastep.PNG" alt="json_sas_datastep.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 13:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701523#M214829</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-11-25T13:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701531#M214831</link>
      <description>&lt;P&gt;Never tried to use the data step debugger.&lt;/P&gt;
&lt;P&gt;But the statement you have split over lines 10 and 11 needs to be AFTER the statement you have on line 12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the right side of that photograph is supposed to show your data then it looks like the variable with the JSON text is named CONTACTPROGRESS and not JSON.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 18:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701531#M214831</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-25T18:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701550#M214838</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all thank you for your time on this.&lt;/P&gt;
&lt;P&gt;I have reviewed thoroughly your code and I understood exactly what your were trying to achieve.&lt;/P&gt;
&lt;P&gt;I did the same this for my part, I located the file in the disk that your code creates.&lt;/P&gt;
&lt;P&gt;In the final datastep, I can see that you are using only the ID column and not all the others (in your example sex, weight etc.).&lt;/P&gt;
&lt;P&gt;Is this something you did on purpose and the code automatically read the columns or this is something that i should do explicitly in order to view the rest of the data?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 15:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701550#M214838</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-11-25T15:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701551#M214839</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/309333"&gt;@vfarmak&lt;/a&gt;&amp;nbsp;In that final step where I have a&amp;nbsp;&lt;STRONG&gt;length&lt;/STRONG&gt; statement only for ID, the remaining columns are being read from the JSON library via the&amp;nbsp;&lt;STRONG&gt;set&lt;/STRONG&gt; statement.&amp;nbsp; This code does not presume knowledge of the column names/attributes that come from that JSON -- but as you can see in the final result, the data is there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nested JSON structures might require more code and join/merge operations for related tables that the JSON engine will create based on structure.&amp;nbsp; The code from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;will read all of the values regardless of nesting structure, and is a good approach when you have no idea of the data structure/contents.&amp;nbsp; But my approach does take advantage of the JSON engine ability to automatically assign the proper variable types and lengths based on the data values.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Nov 2020 15:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/701551#M214839</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2020-11-25T15:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703390#M215506</link>
      <description>&lt;P&gt;Greetings&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;I researched your answers in detail and I flattened the objects not only in EG but also in DI.&lt;/P&gt;
&lt;P&gt;Thank you very much for your effort in this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One last question: Can I find material related to the libraries and the operations that they offer? For example in the Json Library I found the property all_data which stores all the data in a sas dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 15:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703390#M215506</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-12-03T15:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703391#M215507</link>
      <description>&lt;P&gt;Also&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;I tried also to mark your answer as solution, but unfortunately the thread only allows one answer as a solution.&lt;/P&gt;
&lt;P&gt;Both&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;have answered to the topic. Is any way to mark also your answer&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;as a solution?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 15:08:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703391#M215507</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-12-03T15:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703421#M215523</link>
      <description>No, only one solution allowed, and I'm happy to give Tom credit.  But I can edit Tom's solution to reference my reply which might help future readers.</description>
      <pubDate>Thu, 03 Dec 2020 15:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703421#M215523</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2020-12-03T15:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing Json Array stored in SAS Column [SAS DI]</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703424#M215525</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp;The truth is that you both deserve the credit. Unfortunately the portal does not give the option to mark both answers as solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I totally agree with you, you should edit the post and also include your reference as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Dec 2020 15:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-Json-Array-stored-in-SAS-Column-SAS-DI/m-p/703424#M215525</guid>
      <dc:creator>vfarmak</dc:creator>
      <dc:date>2020-12-03T15:53:01Z</dc:date>
    </item>
  </channel>
</rss>

