<?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 a JASON File in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768137#M243609</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should use PROC JSON and PROC HTTP as explained in this paper:&lt;/P&gt;
&lt;P&gt;paper: &lt;A href="https://support.sas.com/resources/papers/proceedings17/0856-2017.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings17/0856-2017.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Paper 856-2017&lt;BR /&gt;Parsing JSON with SAS® in 2017&lt;BR /&gt;John Kennedy, Mesa Digital&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT] the paper also uses the JSON LIBNAME engine and contains an example where data is retrieved from a JSON-endpoint (URL).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Thu, 16 Sep 2021 13:58:40 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2021-09-16T13:58:40Z</dc:date>
    <item>
      <title>Parsing a JSON File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768136#M243608</link>
      <description>&lt;P&gt;Hi I have a JSON file&amp;nbsp; with a&amp;nbsp; field which i want to parse&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Field Name:JOURNEY_RESPONSES&lt;BR /&gt;{"CPAT_Q2":[{"borrower":"primaryBorrower","age":57,"province":"ON"},{"borrower":"coBorrower1","age":53,"province":"ON"}],"CPAT_Q4LOCHELOC":{"balanceAmt":150000,"paymentAmt":500,"paymentFrequency":"MONTHLY","limitAmt":150000,"revolvingLimitAmt":150000,"termAmt":70000,"clkReferenceNumber":"12345678-01"},"CPAT_Q5":[{"borrower":"primaryBorrower","income":60000},{"borrower":"coBorrower1","income":60000}],"CPAT_Q5_COMBINED":{"savings":150000,"expenses":2000}}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and i want something like&amp;nbsp; this:&lt;/P&gt;
&lt;P&gt;borrower1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;age1&amp;nbsp; &amp;nbsp; province1&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;borrower2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; age2&amp;nbsp; &amp;nbsp; province2&lt;/P&gt;
&lt;P&gt;primaryBorrower&amp;nbsp; &amp;nbsp; &amp;nbsp; 57&amp;nbsp; &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;coBorrower1&amp;nbsp; &amp;nbsp; &amp;nbsp; 53&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; on&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what i am doing&amp;nbsp; is this but it only&amp;nbsp; gives me&amp;nbsp; the data&amp;nbsp; of the co-borrower&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do index=1 to countw(JOURNEY_RESPONSES,'{,}','q');&lt;BR /&gt;pair = scan(JOURNEY_RESPONSES,index,'{,}','q');&lt;BR /&gt;name = dequote(scan(pair,1,':','q'));&lt;BR /&gt;value = dequote(scan(pair,2,':','q'));&lt;BR /&gt;select (name);&lt;BR /&gt;when ('borrower') Borrower=value; &lt;BR /&gt;when ('age') Age=input(value,2.);&lt;BR /&gt;when ('province') Province=value;&lt;BR /&gt;when ('clkReferenceNumber') CR_REF_Number=value;&lt;BR /&gt;otherwise put 'NOTE: Unknown field. ' pair=;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can i fix this, any advice please?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 14:46:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768136#M243608</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2021-09-16T14:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a JASON File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768137#M243609</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should use PROC JSON and PROC HTTP as explained in this paper:&lt;/P&gt;
&lt;P&gt;paper: &lt;A href="https://support.sas.com/resources/papers/proceedings17/0856-2017.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings17/0856-2017.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Paper 856-2017&lt;BR /&gt;Parsing JSON with SAS® in 2017&lt;BR /&gt;John Kennedy, Mesa Digital&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;[EDIT] the paper also uses the JSON LIBNAME engine and contains an example where data is retrieved from a JSON-endpoint (URL).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 13:58:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768137#M243609</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-09-16T13:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a JSON File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768180#M243629</link>
      <description>&lt;P&gt;I am not exactly clear one what you want as output from the data. The example you supply only shows part of the data in the output. I suspect you want more output from the data. I am able to replicate what you say you want based on the supplied example output. I hope that code I am supplying will allow you to get an idea of how to solve your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I put your JSON file into the file named "sasComm768136.json". From there, I ran this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname x json './sasComm768136.json';

data temp(drop=ordinal_root ordinal_cpat_q2 borrower age province);
set x.cpat_q2 end=lastOne;
retain borrower1 age1 province1;
if (_N_ eq 1)
   then do;
       borrower1 = borrower;
	   age1 = age;
	   province1 = province;
     end;
   else do;
       borrower2 = borrower;
	   age2 = age;
	   province2 = province;
     end;
  if lastOne
     then do;
       output;
	   end;
run;

proc print data=work.temp; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This produced:&lt;/P&gt;
&lt;PRE&gt; Obs       borrower1       age1    province1     borrower2     age2    province2
   1     primaryBorrower     57        ON        coBorrower1     53        ON&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Sep 2021 19:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768180#M243629</guid>
      <dc:creator>BillM_SAS</dc:creator>
      <dc:date>2021-09-16T19:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a JSON File</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768183#M243631</link>
      <description>&lt;P&gt;Thanks BillM_SAS,&lt;/P&gt;
&lt;P&gt;the jason file has more fields&amp;nbsp; that i need to&amp;nbsp; output actually&lt;/P&gt;
&lt;P&gt;so lets say the original&amp;nbsp; file has 3&amp;nbsp; fields&amp;nbsp; A,&amp;nbsp; B. and&amp;nbsp; Joruney_Response&amp;nbsp; and as an output i want&lt;/P&gt;
&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Borrower1&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;age1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; province1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; borrower2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; age2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; province2&lt;/P&gt;
&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 44&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; primaryborrower&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;57&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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; coborrower1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 53&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; on&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Sep 2021 19:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Parsing-a-JSON-File/m-p/768183#M243631</guid>
      <dc:creator>Tal</dc:creator>
      <dc:date>2021-09-16T19:30:55Z</dc:date>
    </item>
  </channel>
</rss>

