<?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: Need help to loop, read, write dataset after JSON file is SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/670149#M201130</link>
    <description>Is the JSON from an API response?</description>
    <pubDate>Fri, 17 Jul 2020 15:27:41 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-07-17T15:27:41Z</dc:date>
    <item>
      <title>Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669297#M200758</link>
      <description>&lt;P&gt;I am a beginner for this and working on old SAS version and I am not familiar DS2 ( although I saw many great posts and I just not able to get it to work the way I want)&amp;nbsp; I am using INFILE and able to follow some instructions written by others and load the data into SAS.&amp;nbsp; I am honestly looking at the many posts and confused.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename rept "out.json";&lt;/P&gt;&lt;P&gt;data x;&lt;BR /&gt;infile rept lrecl=320000 dsd dlm='{}[],';&lt;BR /&gt;input x : $400. @@;&lt;BR /&gt;if not missing(x);&lt;BR /&gt;run;&lt;BR /&gt;data want;&lt;BR /&gt;set x;&lt;BR /&gt;name=dequote(strip(scan(x,1,':','mq')));&lt;BR /&gt;value=dequote(strip(scan(x,-1,':','mq')));&lt;/P&gt;&lt;P&gt;run;&lt;BR /&gt;proc print data=want;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&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;"MetaData" :&lt;/TD&gt;&lt;TD&gt;MetaData&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"ResponseTime" : "2020-07-08 15:21:42"&lt;/TD&gt;&lt;TD&gt;ResponseTime&lt;/TD&gt;&lt;TD&gt;7/8/2020 15:21&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"StatusType" : "COMPLETE"&lt;/TD&gt;&lt;TD&gt;StatusType&lt;/TD&gt;&lt;TD&gt;COMPLETE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"PriceAsOfDateTime" : "2020-05-29 19:00:00"&lt;/TD&gt;&lt;TD&gt;PriceAsOfDateTime&lt;/TD&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"ProductResults" :&lt;/TD&gt;&lt;TD&gt;ProductResults&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Product" : "ABC EDF XXX&amp;nbsp; 3/1 2/2/5"&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Results" :&lt;/TD&gt;&lt;TD&gt;Results&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Price" : 1.00921875&lt;/TD&gt;&lt;TD&gt;Results&lt;/TD&gt;&lt;TD&gt;1.00921875&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Coupon" : 0.01&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;TD&gt;0.01&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Price" : 1.01171875&lt;/TD&gt;&lt;TD&gt;Price&lt;/TD&gt;&lt;TD&gt;1.01171875&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Coupon" : 0.01125&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;TD&gt;0.01125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Price" : 1.01421875&lt;/TD&gt;&lt;TD&gt;Price&lt;/TD&gt;&lt;TD&gt;1.01421875&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Coupon" : 0.0125&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;TD&gt;0.0125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Product" : "ABC EDF XXX&amp;nbsp; 3/1 10/5/5"&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Results" :&lt;/TD&gt;&lt;TD&gt;Results&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Price" : 1.00921875&lt;/TD&gt;&lt;TD&gt;Results&lt;/TD&gt;&lt;TD&gt;1.04185547&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Coupon" : 0.01&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;TD&gt;0.0275&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Price" : 1.01171875&lt;/TD&gt;&lt;TD&gt;Price&lt;/TD&gt;&lt;TD&gt;1.04436524&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Coupon" : 0.01125&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;TD&gt;0.02875&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Price" : 1.01421875&lt;/TD&gt;&lt;TD&gt;Price&lt;/TD&gt;&lt;TD&gt;1.046875&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"Coupon" : 0.0125&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;TD&gt;0.03&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;Output I want.&amp;nbsp; How can I get to that?&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;PriceAsOfDateTime&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Results&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;&lt;TD&gt;1.00921875&lt;/TD&gt;&lt;TD&gt;0.01&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;&lt;TD&gt;1.01171875&lt;/TD&gt;&lt;TD&gt;0.01125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;&lt;TD&gt;1.01421875&lt;/TD&gt;&lt;TD&gt;0.0125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;&lt;TD&gt;1.04185547&lt;/TD&gt;&lt;TD&gt;0.0275&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;&lt;TD&gt;1.04436524&lt;/TD&gt;&lt;TD&gt;0.02875&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;&lt;TD&gt;1.046875&lt;/TD&gt;&lt;TD&gt;0.03&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;</description>
      <pubDate>Tue, 14 Jul 2020 20:19:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669297#M200758</guid>
      <dc:creator>niejung</dc:creator>
      <dc:date>2020-07-14T20:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669299#M200759</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename rept "out.json";
/*if fields are text */
data x;
Length name $32. Value $200;
infile rept lrecl=320000 dsd dlm='{}[],';
input x : $400. @@;
if not missing(x);
name=dequote(strip(scan(x,1,':','mq')));
value=dequote(strip(scan(x,-1,':','mq')));
run;
proc transpose data = x out=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Did you try libname json&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lestmtsglobal&amp;amp;docsetTarget=n1jfdetszx99ban1rl4zll6tej7j.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lestmtsglobal&amp;amp;docsetTarget=n1jfdetszx99ban1rl4zll6tej7j.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 20:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669299#M200759</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-07-14T20:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669310#M200765</link>
      <description>&lt;P&gt;libname json is not available for me to use.&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":loudly_crying_face:"&gt;😭&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 21:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669310#M200765</guid>
      <dc:creator>niejung</dc:creator>
      <dc:date>2020-07-14T21:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669313#M200766</link>
      <description>&lt;P&gt;OP says they were on an older version.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;OP can you specify what version exactly? The following code will share your version.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're on a slightly later version there are DS2 options but I admit that I always found the data step simpler.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc product_status;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jul 2020 21:30:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669313#M200766</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-14T21:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669322#M200769</link>
      <description>&lt;P&gt;Will this help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Base SAS Software ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;Image version information: 9.04.01M3P060315&lt;BR /&gt;For SAS/STAT ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/GRAPH ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/ETS ...&lt;BR /&gt;Custom version information: 14.1&lt;BR /&gt;For SAS/FSP ...&lt;BR /&gt;Custom version information: 9.4_M3&lt;BR /&gt;For SAS/OR ...&lt;BR /&gt;Custom version information: 14.1&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 21:55:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669322#M200769</guid>
      <dc:creator>niejung</dc:creator>
      <dc:date>2020-07-14T21:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669327#M200773</link>
      <description>Yeah, 9.4M4 has the JSON support, one version up. It's been around since 2016 so your org is definitely due for an upgrade.&lt;BR /&gt;&lt;BR /&gt;I'll see if I can find some time later tonight to test this, but with RETAIN and some coding you can get what you need fairly easily. Could you attach an exact example of the JSON response? If it's via a public API the link is fine too.</description>
      <pubDate>Tue, 14 Jul 2020 22:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669327#M200773</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-14T22:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669329#M200774</link>
      <description>&lt;P&gt;Attached.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;My thought was to split into 2 datasets.&amp;nbsp; One is for status (top 6 rows) and details on rest of them.&lt;/P&gt;&lt;P&gt;then try to use SQL builder to merge to table together.&amp;nbsp; So far I am not moving anywhere.&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":tired_face:"&gt;😫&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jul 2020 22:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669329#M200774</guid>
      <dc:creator>niejung</dc:creator>
      <dc:date>2020-07-14T22:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669350#M200781</link>
      <description>&lt;P&gt;This is what I did so far.&amp;nbsp; I did try to use DS2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Put some JSON in a macro variable for use in testing */&lt;/P&gt;&lt;P&gt;%let json= '{&lt;BR /&gt;"PricingRequestMetaData": {&lt;BR /&gt;"CorrelationIdentifier": "949cf51d-3689-4d51-966f-8a193fd1487c",&lt;BR /&gt;"ResponseTime": "2020-07-14 18:17:53",&lt;BR /&gt;"PricingStatusType": "COMPLETE"&lt;BR /&gt;},&lt;BR /&gt;"PricingResponsePayload": {&lt;BR /&gt;"PriceAsOfDateTime": "2020-05-29 19:00:00",&lt;BR /&gt;"BenchmarkSecurityProductResults": [&lt;BR /&gt;{&lt;BR /&gt;"BenchmarkSecurityProduct": "FHLMC ARM CMS 3/1 2/2/5",&lt;BR /&gt;"CouponResults": [&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.00921875,&lt;BR /&gt;"SecurityCoupon": 0.01&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01171875,&lt;BR /&gt;"SecurityCoupon": 0.01125&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01421875,&lt;BR /&gt;"SecurityCoupon": 0.0125&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01671875,&lt;BR /&gt;"SecurityCoupon": 0.01375&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"BenchmarkSecurityProduct": "FHLMC ARM CMS 5/1 2/2/5",&lt;BR /&gt;"CouponResults": [&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.00980469,&lt;BR /&gt;"SecurityCoupon": 0.01&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01375977,&lt;BR /&gt;"SecurityCoupon": 0.01125&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01771485,&lt;BR /&gt;"SecurityCoupon": 0.0125&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}';&lt;/P&gt;&lt;P&gt;proc ds2;&lt;BR /&gt;data tokens/overwrite=yes;&lt;BR /&gt;dcl package json j();&lt;BR /&gt;dcl nchar(1024) token;&lt;BR /&gt;dcl int tokenType;&lt;BR /&gt;dcl char(1) string number bool_true bool_false delimiter;&lt;BR /&gt;method init();&lt;BR /&gt;dcl varchar(1000000) json;&lt;BR /&gt;dcl nchar(1024) thisVar;&lt;BR /&gt;dcl int rc parseFlags;&lt;BR /&gt;/* JSON for prototyping */&lt;BR /&gt;json=%superq(json);&lt;BR /&gt;rc = j.createParser();&lt;BR /&gt;if (rc) then do;&lt;BR /&gt;put 'Error' rc= ': Could not create JSON parser.';&lt;BR /&gt;stop;&lt;BR /&gt;end;&lt;BR /&gt;rc = j.setParserInput(json);&lt;BR /&gt;if (rc) then do;&lt;BR /&gt;put 'Error' rc= ': setParserInput failed.';&lt;BR /&gt;stop;&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Use the parser to parse the JSON */&lt;BR /&gt;/* RC of 0 means all went well. Otherwise, an error occurred */&lt;BR /&gt;do until (rc ne 0);&lt;BR /&gt;j.getNextToken( rc, token, tokenType, parseFlags );&lt;BR /&gt;string=if j.isstring(tokenType) then 'Y' else 'N';&lt;BR /&gt;number=if j.isnumeric(tokenType) then 'Y' else 'N';&lt;BR /&gt;bool_true=if j.isbooleantrue(tokenType) then 'Y' else 'N';&lt;BR /&gt;bool_false=if j.isbooleanfalse(tokenType) then 'Y' else 'N';&lt;BR /&gt;delimiter=if tokenType in (16,32,64,128) then 'Y' else 'N';&lt;BR /&gt;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;enddata;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%_eg_conditional_dropds(WORK.QUERY_FOR_FINAL);&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY_FOR_FINAL AS&lt;BR /&gt;SELECT t1.token,&lt;BR /&gt;t1.tokenType,&lt;BR /&gt;t1.string,&lt;BR /&gt;t1.number,&lt;BR /&gt;t1.bool_true,&lt;BR /&gt;t1.bool_false,&lt;BR /&gt;t1.delimiter&lt;BR /&gt;FROM WORK.FINAL t1&lt;BR /&gt;WHERE t1.tokenType &amp;gt; 128;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;proc print data=WORK.QUERY_FOR_FINAL;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I create data format like below:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PriceAsOfDateTime&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Results&lt;/TD&gt;&lt;TD&gt;Coupon&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;&lt;TD&gt;1.00921875&lt;/TD&gt;&lt;TD&gt;0.01&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;&lt;TD&gt;1.01171875&lt;/TD&gt;&lt;TD&gt;0.01125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;&lt;TD&gt;1.01421875&lt;/TD&gt;&lt;TD&gt;0.0125&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;&lt;TD&gt;1.04185547&lt;/TD&gt;&lt;TD&gt;0.0275&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;&lt;TD&gt;1.04436524&lt;/TD&gt;&lt;TD&gt;0.02875&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;&lt;TD&gt;1.046875&lt;/TD&gt;&lt;TD&gt;0.03&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 15 Jul 2020 01:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669350#M200781</guid>
      <dc:creator>niejung</dc:creator>
      <dc:date>2020-07-15T01:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669937#M201046</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data process_request;

	infile '/home/fkhurshed/sampledata.txt';
	input;
	str=_infile_;
	
	length CorrelationIdentifier $50.;
	retain CorrelationIdentifier ResponseTime PricingStatusType PriceAsofDateTime 
		BenchmarkSecurityProduct ArmPrice;

	if index(str, "CorrelationIdentifier")&amp;gt;0 then
		CorrelationIdentifier=scan(str, 3, ':"');
	else if index(str, "ResponseTime")&amp;gt;0 then
		ResponseTime=input(scan(str, 3, '"'), anydtdtm.);
	else if index(str, "PricingStatusType")&amp;gt;0 then
		PricingStatusType=scan(str, 3, '"');
	else if index(str, "PriceAsOfDateTime")&amp;gt;0 then
		PriceAsOfDateTime=input(scan(str, 3, '"'), anydtdtm.);
	else if index(str, "BenchmarkSecurityProduct")&amp;gt;0 then
		BenchmarkSecurityProduct=scan(str, 3, '"');
	else if index(str, "ArmPrice")&amp;gt;0 then
		ArmPrice=input(scan(str, 2, ':,'), best12.);
	else if index(str, "SecurityCoupon")&amp;gt;0 then
		do;
			SecurityCoupon=input(scan(str, 2, ':,'), best12.);
			output;
			ArmPrice=.;
		end;
	format responseTime PriceAsOfDateTime datetime20. ArmPrice 12.8 SecurityCoupon 
		12.5;
		
	drop str;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This processes your demo output. As long as it has the same format and only one&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;BenchmarkSecurityProduct&lt;/CODE&gt; per response you're good. If you need to consider multiple the data step would need to be modified but it's doable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/336655"&gt;@niejung&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is what I did so far.&amp;nbsp; I did try to use DS2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* Put some JSON in a macro variable for use in testing */&lt;/P&gt;
&lt;P&gt;%let json= '{&lt;BR /&gt;"PricingRequestMetaData": {&lt;BR /&gt;"CorrelationIdentifier": "949cf51d-3689-4d51-966f-8a193fd1487c",&lt;BR /&gt;"ResponseTime": "2020-07-14 18:17:53",&lt;BR /&gt;"PricingStatusType": "COMPLETE"&lt;BR /&gt;},&lt;BR /&gt;"PricingResponsePayload": {&lt;BR /&gt;"PriceAsOfDateTime": "2020-05-29 19:00:00",&lt;BR /&gt;"BenchmarkSecurityProductResults": [&lt;BR /&gt;{&lt;BR /&gt;"BenchmarkSecurityProduct": "FHLMC ARM CMS 3/1 2/2/5",&lt;BR /&gt;"CouponResults": [&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.00921875,&lt;BR /&gt;"SecurityCoupon": 0.01&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01171875,&lt;BR /&gt;"SecurityCoupon": 0.01125&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01421875,&lt;BR /&gt;"SecurityCoupon": 0.0125&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01671875,&lt;BR /&gt;"SecurityCoupon": 0.01375&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"BenchmarkSecurityProduct": "FHLMC ARM CMS 5/1 2/2/5",&lt;BR /&gt;"CouponResults": [&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.00980469,&lt;BR /&gt;"SecurityCoupon": 0.01&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01375977,&lt;BR /&gt;"SecurityCoupon": 0.01125&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"ArmPrice": 1.01771485,&lt;BR /&gt;"SecurityCoupon": 0.0125&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}';&lt;/P&gt;
&lt;P&gt;proc ds2;&lt;BR /&gt;data tokens/overwrite=yes;&lt;BR /&gt;dcl package json j();&lt;BR /&gt;dcl nchar(1024) token;&lt;BR /&gt;dcl int tokenType;&lt;BR /&gt;dcl char(1) string number bool_true bool_false delimiter;&lt;BR /&gt;method init();&lt;BR /&gt;dcl varchar(1000000) json;&lt;BR /&gt;dcl nchar(1024) thisVar;&lt;BR /&gt;dcl int rc parseFlags;&lt;BR /&gt;/* JSON for prototyping */&lt;BR /&gt;json=%superq(json);&lt;BR /&gt;rc = j.createParser();&lt;BR /&gt;if (rc) then do;&lt;BR /&gt;put 'Error' rc= ': Could not create JSON parser.';&lt;BR /&gt;stop;&lt;BR /&gt;end;&lt;BR /&gt;rc = j.setParserInput(json);&lt;BR /&gt;if (rc) then do;&lt;BR /&gt;put 'Error' rc= ': setParserInput failed.';&lt;BR /&gt;stop;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* Use the parser to parse the JSON */&lt;BR /&gt;/* RC of 0 means all went well. Otherwise, an error occurred */&lt;BR /&gt;do until (rc ne 0);&lt;BR /&gt;j.getNextToken( rc, token, tokenType, parseFlags );&lt;BR /&gt;string=if j.isstring(tokenType) then 'Y' else 'N';&lt;BR /&gt;number=if j.isnumeric(tokenType) then 'Y' else 'N';&lt;BR /&gt;bool_true=if j.isbooleantrue(tokenType) then 'Y' else 'N';&lt;BR /&gt;bool_false=if j.isbooleanfalse(tokenType) then 'Y' else 'N';&lt;BR /&gt;delimiter=if tokenType in (16,32,64,128) then 'Y' else 'N';&lt;BR /&gt;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;enddata;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%_eg_conditional_dropds(WORK.QUERY_FOR_FINAL);&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY_FOR_FINAL AS&lt;BR /&gt;SELECT t1.token,&lt;BR /&gt;t1.tokenType,&lt;BR /&gt;t1.string,&lt;BR /&gt;t1.number,&lt;BR /&gt;t1.bool_true,&lt;BR /&gt;t1.bool_false,&lt;BR /&gt;t1.delimiter&lt;BR /&gt;FROM WORK.FINAL t1&lt;BR /&gt;WHERE t1.tokenType &amp;gt; 128;&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;P&gt;proc print data=WORK.QUERY_FOR_FINAL;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I create data format like below:&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;PriceAsOfDateTime&lt;/TD&gt;
&lt;TD&gt;Product&lt;/TD&gt;
&lt;TD&gt;Results&lt;/TD&gt;
&lt;TD&gt;Coupon&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;
&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;
&lt;TD&gt;1.00921875&lt;/TD&gt;
&lt;TD&gt;0.01&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;
&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;
&lt;TD&gt;1.01171875&lt;/TD&gt;
&lt;TD&gt;0.01125&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;
&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 2/2/5&lt;/TD&gt;
&lt;TD&gt;1.01421875&lt;/TD&gt;
&lt;TD&gt;0.0125&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;
&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;
&lt;TD&gt;1.04185547&lt;/TD&gt;
&lt;TD&gt;0.0275&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;
&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;
&lt;TD&gt;1.04436524&lt;/TD&gt;
&lt;TD&gt;0.02875&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;5/29/2020 19:00&lt;/TD&gt;
&lt;TD&gt;ABC EDF XXX&amp;nbsp; 3/1 10/5/5&lt;/TD&gt;
&lt;TD&gt;1.046875&lt;/TD&gt;
&lt;TD&gt;0.03&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 17:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/669937#M201046</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-16T17:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/670014#M201080</link>
      <description>&lt;P&gt;This is great!!&amp;nbsp; &amp;nbsp;I was struggle how I can get file into string.&amp;nbsp; Let me play around a little.&amp;nbsp;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_blowing_a_kiss:"&gt;😘&lt;/span&gt;&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;	infile '/home/fkhurshed/sampledata.txt';
	input;
	str=_infile_;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2020 22:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/670014#M201080</guid>
      <dc:creator>niejung</dc:creator>
      <dc:date>2020-07-16T22:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/670149#M201130</link>
      <description>Is the JSON from an API response?</description>
      <pubDate>Fri, 17 Jul 2020 15:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/670149#M201130</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-17T15:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to loop, read, write dataset after JSON file is SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/670372#M201224</link>
      <description>Yes. I saved the response output to a file.&lt;BR /&gt;I was able to fixed the parsing for product information. I am REALLY appreciated your help. I learned so much for this and this is first time doing SAS development.&lt;BR /&gt;&lt;BR /&gt;For the product, I changed to&lt;BR /&gt;Substr(str, index(str,’: ‘), lengthn(str)-38);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 18 Jul 2020 19:59:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-loop-read-write-dataset-after-JSON-file-is-SAS/m-p/670372#M201224</guid>
      <dc:creator>niejung</dc:creator>
      <dc:date>2020-07-18T19:59:42Z</dc:date>
    </item>
  </channel>
</rss>

