🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 06-29-2020 04:37 AM
(2630 views)
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
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
5 REPLIES 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Will keep it in mind 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Ahmed. It works!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;