<?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: generate sas dataset using proc groovy-JSON in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/405410#M66982</link>
    <description>&lt;P&gt;What version of SAS do you have? SAS 9.4 M4 has a JSON libname which may be easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In PROC GROOVY it’s a manual process to parse the items, and I think you need to understand the structure. It’s been a while since I’ve used it though.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Oct 2017 04:02:36 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-10-19T04:02:36Z</dc:date>
    <item>
      <title>Create a SAS data set from JSON file using PROC GROOVY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/405406#M66981</link>
      <description>&lt;P&gt;How do I parse the JSON file to a sas dataset using proc groovy:&lt;/P&gt;
&lt;P&gt;here is my code-&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc groovy;&lt;BR /&gt;add classpath="C:\bin\groovy-2.4.12\lib\groovy-2.4.12.jar";&lt;BR /&gt;add classpath="C:\bin\groovy-2.4.12\lib\groovy-json-2.4.12.jar";&lt;BR /&gt;submit;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;import groovy.json.JsonSlurper;&lt;BR /&gt;def json_string = (new File("C:\\Users\\test.json")).getText();&lt;BR /&gt;def jsonSlurper = new JsonSlurper()&lt;BR /&gt;def json = jsonSlurper.parseText(json_string);&lt;BR /&gt;def testDataList = []&lt;BR /&gt;json.each {&lt;BR /&gt;testDataList.add(jsonSlurper.parseText(it))&lt;BR /&gt;}&lt;BR /&gt;endsubmit;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 04:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/405406#M66981</guid>
      <dc:creator>HabAM</dc:creator>
      <dc:date>2017-10-19T04:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: generate sas dataset using proc groovy-JSON</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/405410#M66982</link>
      <description>&lt;P&gt;What version of SAS do you have? SAS 9.4 M4 has a JSON libname which may be easier.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In PROC GROOVY it’s a manual process to parse the items, and I think you need to understand the structure. It’s been a while since I’ve used it though.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 04:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/405410#M66982</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-19T04:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: generate sas dataset using proc groovy-JSON</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/405420#M66983</link>
      <description>&lt;P&gt;I have 9.4 M2. I know the latest releason has a JSON lib. Thank you for the response.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 06:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/405420#M66983</guid>
      <dc:creator>HabAM</dc:creator>
      <dc:date>2017-10-19T06:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create a SAS data set from JSON file using PROC GROOVY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/472878#M71012</link>
      <description>&lt;P&gt;mehretua,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately this is not possible directly. You will need to use groovy to parse the JSON then write to a file (CSV or similar) in a way that can be read in by SAS. This is probably the best approach for large sets of data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is possible to pass back simply key/value pairs from proc groovy into SAS by using the "exports" special variable which is used to populate SAS macro variables. This is used to pull out an OAuth token in the following example: &lt;A href="https://blogs.sas.com/content/sascom/2013/12/12/how-to-import-twitter-tweets-in-sas-data-step-using-oauth-2-authentication-style/" target="_blank"&gt;https://blogs.sas.com/content/sascom/2013/12/12/how-to-import-twitter-tweets-in-sas-data-step-using-oauth-2-authentication-style/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="sas"&gt;&lt;SPAN style="color: #006400; font-style: italic;"&gt;/* Store bearer token in macro variable 'BEARER_TOKEN' */&lt;/SPAN&gt;
 &lt;SPAN style="color: #000080; font-weight: bold;"&gt;proc groovy&lt;/SPAN&gt; classpath=&lt;SPAN style="color: #a020f0;"&gt;"groovy-all-2.2.1.jar"&lt;/SPAN&gt;;
    submit &lt;SPAN style="color: #a020f0;"&gt;"&amp;amp;JSON_TWEET_FILE."&lt;/SPAN&gt;;
      import groovy.json.JsonSlurper
      def &lt;SPAN style="color: #0000ff;"&gt;input&lt;/SPAN&gt; = new &lt;SPAN style="color: #0000ff;"&gt;File&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;args&lt;SPAN style="color: #66cc66;"&gt;[&lt;/SPAN&gt;&lt;SPAN style="color: #2e8b57; font-weight: bold;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;]&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;.text
      def result = new JsonSlurper&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;.parseText&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;
      println &lt;SPAN style="color: #a020f0;"&gt;"Recieved bearer token: ${result.access_token}"&lt;/SPAN&gt;
      exports.putAt&lt;SPAN style="color: #66cc66;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #a020f0;"&gt;'BEARER_TOKEN'&lt;/SPAN&gt;,result.access_token&lt;SPAN style="color: #66cc66;"&gt;)&lt;/SPAN&gt;
    endsubmit;
 &lt;SPAN style="color: #000080; font-weight: bold;"&gt;quit&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is also possible to return a comma separated list of strings using a list in groovy. See &lt;A href="http://support.sas.com/resources/papers/proceedings17/SAS0245-2017.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings17/SAS0245-2017.pdf&lt;/A&gt; for an example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this helps. I've been exploring proc groovy on our SAS 9.4m4 linux environment. It looks suitable for pulling simple information from complex JSON. I'd be interested in seeing examples of writing more complex JSON.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hamish&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jun 2018 06:27:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Create-a-SAS-data-set-from-JSON-file-using-PROC-GROOVY/m-p/472878#M71012</guid>
      <dc:creator>hamishcarpenter</dc:creator>
      <dc:date>2018-06-25T06:27:20Z</dc:date>
    </item>
  </channel>
</rss>

