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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.