Folks,
I'm attempting to load some Json data into SAS to carry out some manipulation.
filename in "\\jsonlocation\\Simdata.json";
filename map 'my.map';
libname in json map=map automap=reuse;
proc datasets; copy in=in out=test;
run;
When I run the commands above SAS reads in the json file and parses it into various different SAS datasets.
These are located in the libname called in.
However, if I want to save these datasets to carry out some manipulation etc. I have to use the proc datasets command to put them into the location marked test.
Could anyone let me know, where the libname in is located.
It appears to be in the same location as to where my json file is, so in truth are these not 'real' sas datsets but rather a SAS equivalent of the parsed json file?
Any information would be great.
It will follow every other procedure/datastep:
filename in "\\jsonlocation\\Simdata.json"; filename map 'my.map'; libname in_json json map=map automap=reuse;
libname out_json '\\somwhere\tosaveto'; proc datasets copy in=in_json out=out_json.test; run;
You would specifiy a path to a libname, then use that libname in your statement to save the datasets to the given libname. There were various errors in that code you provided, so I don't see how you could be running it and getting output (i.e. test is not a libname, so you can't copy to, colon after datasets).
Also, avoid using "in" and "out" as libname's, these are keywords in SAS and make reading the code very hard.
filename in "\\jsonlocation\\Simdata.json";
filename map 'my.map';
libname in_json json map=map automap=reuse;
Running this piece of code produces an error of the following nature.
Relating to an invalid filename.
However, this works
filename in_json "\\jsonlocation\\Simdata.json";
filename map 'my.map';
libname in_json json map=map automap=reuse;
I presume your file name location name must be the same for your libname location for reading in the json
Quite possibly, I have nothing to test it on. The key point I was making is highlighted below:
filename in_jsaon "\\jsonlocation\\Simdata.json"; filename map 'my.map'; libname in_json json map=map automap=reuse;
libname out_json '\\somwhere\tosaveto'; proc datasets copy in=in_json out=out_json.test; run;
It's been a little while since I used it but I think data sets created with the JSON engine are read-only. If you want to change them you either need to do as you're doing now and copy them to another library or (which I would recommend) change the JSON map
Hi Chris,
I just want to make sure when I read the json file into Sas that they're not saved to some common area where everyone can view them.
The LIBNAME statement with the JSON engine is what is allowing SAS to read the data from the JSON file as if were a collection of SAS datasets. Similar to how the ORACLE engine allows you to read Oracle tables/views as if they were SAS datasets.
It is not STORED anywhere.
You don't have to use PROC COPY to read the data you could just as easily run your analysis on the data directly without ever writing them back out as stored SAS datasets. For example if one of the "datasets" in your JSON file was named mytable you could run PROC MEANS on it.
proc means data=IN.mytable ;
run;
It looks like you missed an option.
ibname in json fileref=in .....
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.