I am trying to import a NDJSON file from SAS but I am unable to do so using proc json statement. Is there any other way to read in such file?
Link to NDJSON file I am trying to read in SAS is https://bcda.cms.gov/assets/data/Patient.ndjson
I answered similar question last week.
Try converting the NDJSON into a JSON, then using SAS to import it
filename jsonl url "https://bcda.cms.gov/assets/data/Patient.ndjson";
filename json temp;
filename map temp;
/* 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;
/* Check resulted Library and data sets */
proc contents data=json._all_; run;
Hope this helps,
Ahmed
I answered similar question last week.
Try converting the NDJSON into a JSON, then using SAS to import it
filename jsonl url "https://bcda.cms.gov/assets/data/Patient.ndjson";
filename json temp;
filename map temp;
/* 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;
/* Check resulted Library and data sets */
proc contents data=json._all_; run;
Hope this helps,
Ahmed
Nice code!
The strip() function does nothing as used though.
Also, if you want you can have a single line
do until (EOF);
input;
LINE = cats( _infile_, ifc(EOF,,',') );
put LINE;
end;
Why proc json? Have you tried this?
filename RAW "c:\temp\raw.json";
proc http method = "get"
url = "https://.......json"
out = RAW;
run;
libname X json fileref=RAW ;
proc copy in=X out=WORK;
run;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: