<?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 Re: Read JSON without flattening ARRAYS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867315#M342543</link>
    <description>&lt;P&gt;I want a single column PROC in the SAS dataset that contains value PROC =&amp;nbsp;&lt;SPAN&gt;"[ 2800, 2980, 4090, 4170 ]".&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 30 Mar 2023 19:28:24 GMT</pubDate>
    <dc:creator>Haris</dc:creator>
    <dc:date>2023-03-30T19:28:24Z</dc:date>
    <item>
      <title>Read JSON without flattening ARRAYS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867306#M342538</link>
      <description>&lt;P&gt;I am trying to read a JSON file with 30 arrays.&amp;nbsp; Here's the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;filename in "Source.json";
filename map 'WorkingMap.Map';
libname in json map=Map automap=reuse;

libname j json "Source.json" map=Map;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By default this syntax creates a separate table for each array.&amp;nbsp; For the example below, the code above creates Proc1-Proc4 columns in a table PROC with Ordinal_Root link to the main ROOT dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;"proc": [
      2800,
      2980,
      4090,
      4170
    ],&lt;/PRE&gt;
&lt;P&gt;I have to merge multiple files into one for my purposes and also aggregate multiple columns into one.&amp;nbsp; On top of that, I am processing dozens of JSONS that need to be stacked to there's a ton of re-merging going on.&lt;BR /&gt;&lt;BR /&gt;Is there an option or a mapping method/trick to read arrays as simple text strings?&amp;nbsp; For the PROC example above, rather than a dedicated separate table with multiple columns for each value of the array, I would like a single column that contains them all in one cell just like in the JSON:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;[ 2800, 2980, 4090, 4170 ]&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Need help!!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 18:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867306#M342538</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2023-03-30T18:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Read JSON without flattening ARRAYS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867312#M342541</link>
      <description>&lt;P&gt;I'm confused as to what you want as the SAS data from reading that JSON.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you read the data:&lt;/P&gt;
&lt;PRE&gt;"proc": [
      2800,
      2980,
      4090,
      4170
    ],&lt;/PRE&gt;
&lt;P&gt;Do you want the output to be a SAS dataset with one record and one character variable named PROC with the value "[ 2800, 2980, 4090, 4170 ]" ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want the output to be a SAS dataset with one numeric variable PROC with four records, i.e.:&lt;/P&gt;
&lt;PRE&gt;PROC
2800
2980
4090
4170&lt;/PRE&gt;
&lt;P&gt;Or do you want something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be sure to check out the alldata table, that might be helpful to you.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 19:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867312#M342541</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-30T19:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read JSON without flattening ARRAYS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867315#M342543</link>
      <description>&lt;P&gt;I want a single column PROC in the SAS dataset that contains value PROC =&amp;nbsp;&lt;SPAN&gt;"[ 2800, 2980, 4090, 4170 ]".&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 19:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867315#M342543</guid>
      <dc:creator>Haris</dc:creator>
      <dc:date>2023-03-30T19:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Read JSON without flattening ARRAYS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867337#M342547</link>
      <description>&lt;P&gt;I don't think you can do that with the JSON engine.&amp;nbsp; You basically want to read an array of JSON elements into a single character variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you write your own program to parse the json file using INPUT, you should be able to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or maybe you could pre-process the JSON file to convert the arrays into string values, i.e. change:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;"proc": [
      2800,
      2980,
      4090,
      4170
    ],&lt;/PRE&gt;
&lt;P&gt;to:&lt;/P&gt;
&lt;PRE&gt;"proc": "[
      2800,
      2980,
      4090,
      4170
    ]",&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Mar 2023 20:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-JSON-without-flattening-ARRAYS/m-p/867337#M342547</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-30T20:03:15Z</dc:date>
    </item>
  </channel>
</rss>

