<?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: Parsing json data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399777#M278544</link>
    <description>&lt;P&gt;See if this helps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/?postid=710499380" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/?postid=710499380&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have not tried this code yet since I normally use JSON engines outside of SAS but 9.4M4 has a new libname engine for JSON.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Sep 2017 13:06:41 GMT</pubDate>
    <dc:creator>AlanC</dc:creator>
    <dc:date>2017-09-29T13:06:41Z</dc:date>
    <item>
      <title>Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399736#M278541</link>
      <description>&lt;P&gt;Hi, I'm trying to get the attached data into SAS in order to analyse&amp;nbsp;it alongside&amp;nbsp;another data set. I don't have any experience working with json formatted data, so am having a lot of difficulty trying to get it in in a usable format. Trawled through the boards and found this solution (with edits for my data structure):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data x;&lt;BR /&gt;infile 'C:\Desktop\psc.txt' dsd lrecl=30000000 dlm='{[:,';&lt;BR /&gt;input x : $2000.@@;&lt;BR /&gt;run;&lt;BR /&gt;data temp;&lt;BR /&gt;merge x x(firstobs=2 rename=(x=_x));&lt;BR /&gt;if lowcase(x) in ("company_number","data__address__address_line_1","data__address__address_line_2","data__address__care_of","data__address__country","data__address__locality","data__address__po_box","data__address__postal_code","data__address__premises","data__address__region","data__ceased_on","data__country_of_residence","data__date_of_birth__month","data__date_of_birth__year","data__description","data__etag","data__exemptions__psc_exempt_as_shares_admitted_on_market__exemption_type","data__exemptions__psc_exempt_as_shares_admitted_on_market__items","data__exemptions__psc_exempt_as_trading_on_regulated_market__exemption_type","data__exemptions__psc_exempt_as_trading_on_regulated_market__items","data__exemptions_count","data__generated_at","data__identification__country_registered","data__identification__legal_authority","data__identification__legal_form","data__identification__place_registered","data__identification__registration_number","data__kind","data__links__self","data__name","data__name_elements__forename","data__name_elements__honours","data__name_elements__middle_name","data__name_elements__surname","data__name_elements__title","data__nationality","data__natures_of_control","data__notified_on","data__persons_of_significant_control_count","data__statement","data__statements_count");&lt;BR /&gt;run;&lt;BR /&gt;data temp;&lt;BR /&gt;set temp;&lt;BR /&gt;if lowcase(x)='company_number' then group+1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc transpose data=temp out=want(drop=_:);&lt;BR /&gt;by group;&lt;BR /&gt;id x;&lt;BR /&gt;var _x;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently the ouput is a series 'group', and then the company numbers that have been successfully extracted. I'm a beginner with SAS programming language, but it seems like the other sets of data aren't defined in the code, but I'm really stuck with how to fix it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, Ian&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 11:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399736#M278541</guid>
      <dc:creator>ICL1986</dc:creator>
      <dc:date>2017-09-29T11:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399742#M278542</link>
      <description>&lt;P&gt;This is a bit of a tough ask if you're a beginner in SAS - in my experience the best way to parse JSON is to use the Proc DS2 JSON parser. There's a good example in this artice&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like your JSON is fairly straightforward so if you give it a try and post again if you have any problems.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 11:20:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399742#M278542</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-29T11:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399773#M278543</link>
      <description>&lt;P&gt;Think that solution's a bit beyond me as well! I'll have an ask around at work to see whether anyone else can give a hand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for you help, Ian&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 13:00:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399773#M278543</guid>
      <dc:creator>ICL1986</dc:creator>
      <dc:date>2017-09-29T13:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399777#M278544</link>
      <description>&lt;P&gt;See if this helps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/?postid=710499380" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2016/12/02/json-libname-engine-sas/?postid=710499380&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have not tried this code yet since I normally use JSON engines outside of SAS but 9.4M4 has a new libname engine for JSON.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 13:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399777#M278544</guid>
      <dc:creator>AlanC</dc:creator>
      <dc:date>2017-09-29T13:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399798#M278545</link>
      <description>&lt;P&gt;Yeah. The best to solve this kind of problem is using JSON engine of LIBNAME statement, if you have SAS 9.4 m4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename x 'c:\temp\psc.txt';
data x;
 infile x recfm=n dlm='{},';
 input x : $2000.@@;
 a=dequote(scan(x,1,':'));
 b=dequote(scan(x,-1,':','m'));
 if anyspace(x)=1 then do;group+1;delete;end;
run;
proc transpose data=x out=want;
by group;
id a;
var b;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Sep 2017 14:08:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399798#M278545</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-09-29T14:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399804#M278546</link>
      <description>&lt;P&gt;This seems to have worked! Thanks so much.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 14:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399804#M278546</guid>
      <dc:creator>ICL1986</dc:creator>
      <dc:date>2017-09-29T14:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399877#M278547</link>
      <description>&lt;P&gt;I found the JSON in the attached psc.txt file is invalid. I modified the file as I think it should be for what you appear to desire (and the modified file is attached to this post). With a valid JSON file, I ran the JSON LIBNAME engine (available in SAS 9.4 maintenance release 4) to produce 4 SAS data sets. I then used the SQL procedure to combine the SAS data sets into records similar to the JSON data. This demonstrates how to reassemble the hierarchical data in the JSON data file that was flatten into SAS data sets. The complete SAS program is included and shows how easy it is to import JSON data into SAS data set using the JSON LIBNAME engine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname x5 json 'psc5.txt';
proc datasets lib=x5; 
     quit;
proc contents data=x5._all_; 
     run;

proc sql;
     create table work.records as
     select root.company_number, data.etag, data.kind, data_links.self,
            data.notified_on, data.statement, data.ceased_on
     from x5.root as root, X5.DATA_LINKS as DATA_LINKS, X5.DATA as data
     where root.ordinal_root = data.ordinal_root and
           data.ordinal_data = data_links.ordinal_data
           ;
     quit;
proc print data=work.records(obs=5); 
     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;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; company_&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Obs&amp;nbsp; number&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; etag&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 10869580&amp;nbsp;&amp;nbsp;&amp;nbsp; f327a09d5a3a08af72b03211f3a2e148814d75dd&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 10869582&amp;nbsp;&amp;nbsp;&amp;nbsp; 83f75b47516bb1c7bac875c7f97134cb51711f2d&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 3 10869588&amp;nbsp;&amp;nbsp;&amp;nbsp; e730a688879c2f724e8c881267497f9b10ba2688&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 4 10869591&amp;nbsp;&amp;nbsp;&amp;nbsp; 83dcecd921dee3f8099bd90a4d355b104ffacc9f&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 5 10869596&amp;nbsp;&amp;nbsp;&amp;nbsp; f570d6220979853777d6bad1418cafd5a4f7c418&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kind&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 persons-with-significant-control-statement&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 persons-with-significant-control-statement&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 3 persons-with-significant-control-statement&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 4 persons-with-significant-control-statement&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 5 persons-with-significant-control-statement&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 /company/10869580/persons-with-significant-control-statements/JZsKO5aylMYj&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 /company/10869582/persons-with-significant-control-statements/5xQ7ZCMaLDHO&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 3 /company/10869588/persons-with-significant-control-statements/rHluQkBUwwXw&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 4 /company/10869591/persons-with-significant-control-statements/rK8w6OtlgY9f&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 5 /company/10869596/persons-with-significant-control-statements/w1mzlYcY-BoB&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; notified_&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ceased_&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Obs&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; statement&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 1 2017-07-17&amp;nbsp;&amp;nbsp; no-individual-or-entity-with-signficant-control&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 2 2017-07-17&amp;nbsp;&amp;nbsp; no-individual-or-entity-with-signficant-control&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 3 2017-07-17&amp;nbsp;&amp;nbsp; no-individual-or-entity-with-signficant-control&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 4 2017-07-17&amp;nbsp;&amp;nbsp; no-individual-or-entity-with-signficant-control&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; 5 2017-07-17&amp;nbsp;&amp;nbsp; no-individual-or-entity-with-signficant-control&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: There were 5 observations read from the data set WORK.RECORDS.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;NOTE: PROCEDURE PRINT used (Total process time):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.04 seconds&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 18:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399877#M278547</guid>
      <dc:creator>BillM_SAS</dc:creator>
      <dc:date>2017-09-29T18:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399890#M278548</link>
      <description>&lt;P&gt;What was wrong with the original file and what did you do to fix it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you just wrap the whole thing in [] with commas?&lt;/P&gt;
&lt;P&gt;So something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   infile 'badfile' end=eof;
   file 'goodfile' ;
   retain sep '[' ;
   input ;
   put sep _infile_ ;
   if eof then put ']';
   sep=',';
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Sep 2017 19:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399890#M278548</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-29T19:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing json data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399893#M278549</link>
      <description>&lt;P&gt;The JSON LIBNAME engine did not like the JSON in the psc.txt file originally posted. I then ran that JSON file through a JSON pretty printer and it also noted the file was invalid. So yes, after I&amp;nbsp;examined the file I added commas and wrapped the contents of the whole file with brackets to make it a valid JSON file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 19:15:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-json-data/m-p/399893#M278549</guid>
      <dc:creator>BillM_SAS</dc:creator>
      <dc:date>2017-09-29T19:15:53Z</dc:date>
    </item>
  </channel>
</rss>

