<?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: Reading ndjson file. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/676499#M203995</link>
    <description>&lt;P&gt;The max length for a var also the _INFILE_ used in the example code is 32767. Many lines in your data are longer than 32767, so the code will not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed the code, so that a line that is longer than 32767 is also processed correctly. The logic is lightly different for the reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Convert the NDJSON to JSON */
data _null_;
  length inputline $ 32767;
  infile jsonl end=eod lrecl=1048576 LENGTH=_ll truncover;
  file json lrecl=1048576;

  if _n_ = 1 then do;
    put '[{"records":['; /* Required for JSON formatting */
  end;

  input @;
  pos = 1;

  do i = 1 to ceil(_ll / 32767);
    input @pos inputline $char32767. @;
    il_l = length(inputline);
    put @pos inputline $varying32767. il_l @;
    pos = i * 32767 + 1;
  end;
  if eod = 0 then do;
    put ",";
  end;

  if eod = 1 then do;
    put;   
    put ']}]'; /* Required for JSON formatting */
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 13 Aug 2020 14:36:47 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2020-08-13T14:36:47Z</dc:date>
    <item>
      <title>Reading ndjson file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/676415#M203950</link>
      <description>&lt;P&gt;I am trying to import a ndjson file into sas using the below solution,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Reading-NDJSON-Newline-Delimited-JSON/m-p/665720" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Reading-NDJSON-Newline-Delimited-JSON/m-p/665720&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;we were able to load&amp;nbsp; a smaller length size file with the above solution, but facing issues while using the same logic&amp;nbsp; with a different file.&lt;/P&gt;
&lt;P&gt;i.e.&amp;nbsp;&lt;A href="https://bcda.cms.gov/assets/data/ExplanationOfBenefit.ndjson" target="_blank"&gt;https://bcda.cms.gov/assets/data/ExplanationOfBenefit.ndjson&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Some lines from the file are getting missed out while import.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
filename jsonl "/bcda/ExplanationOfBenefit.ndjson";

filename json temp;
filename map "/bcda/ExplanationOfBenefit.map";


/* Convert the NDJSON to JSON */
data _null_;
	infile jsonl end=eof;
	file json;
	put '[{"records":['; /* Required for JSON formatting */
	do until (eof);
		input;
		line = STRIP(_infile_);
		if (eof=0) then
			line=cats(line, ',');

		put line;
	end;
	put ']}]'; /* Required for JSON formatting */
	stop;
run;
libname json json automap=create map=map;
proc contents data=json._all_; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 07:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/676415#M203950</guid>
      <dc:creator>Anmolkhandelwal</dc:creator>
      <dc:date>2020-08-13T07:18:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading ndjson file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/676499#M203995</link>
      <description>&lt;P&gt;The max length for a var also the _INFILE_ used in the example code is 32767. Many lines in your data are longer than 32767, so the code will not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I changed the code, so that a line that is longer than 32767 is also processed correctly. The logic is lightly different for the reading.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Convert the NDJSON to JSON */
data _null_;
  length inputline $ 32767;
  infile jsonl end=eod lrecl=1048576 LENGTH=_ll truncover;
  file json lrecl=1048576;

  if _n_ = 1 then do;
    put '[{"records":['; /* Required for JSON formatting */
  end;

  input @;
  pos = 1;

  do i = 1 to ceil(_ll / 32767);
    input @pos inputline $char32767. @;
    il_l = length(inputline);
    put @pos inputline $varying32767. il_l @;
    pos = i * 32767 + 1;
  end;
  if eod = 0 then do;
    put ",";
  end;

  if eod = 1 then do;
    put;   
    put ']}]'; /* Required for JSON formatting */
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Aug 2020 14:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/676499#M203995</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2020-08-13T14:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Reading ndjson file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/728675#M226717</link>
      <description>Hi,&lt;BR /&gt;Thanks for the help.&lt;BR /&gt;Is there any way we can make lrecl=1048576 as dynamic.&lt;BR /&gt;The records length doesn't remain same in the files i am reading in,&lt;BR /&gt;for eg, if first row is of length 7542, the 2nd row can be of a length 381700.&lt;BR /&gt;&lt;BR /&gt;TIA</description>
      <pubDate>Wed, 24 Mar 2021 06:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/728675#M226717</guid>
      <dc:creator>Anmolkhandelwal</dc:creator>
      <dc:date>2021-03-24T06:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Reading ndjson file.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/728680#M226719</link>
      <description>&lt;P&gt;Just make sure LRECL is big enough for the longest line. If lines have different lengths does not matter check your SAS log for something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;NOTE: 1588 records were read from the infile JSONL.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; The minimum record length was 8218.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; The maximum record length was 65536.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;STRONG&gt;One or more lines were truncated.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do not see this message, then all should be ok.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 08:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reading-ndjson-file/m-p/728680#M226719</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2021-03-24T08:04:35Z</dc:date>
    </item>
  </channel>
</rss>

