Would appreciate any help on this matter.
I have a large json file 12 million records, which I've split up into smaller json files for processing efficiency.
I have some code which can process these files, however I would like to include it in a macro so it'll carry out the work for each seperate json file.
%let target=\\location\data\data_set_;
%let n=100000;
data _null_;
if eof then stop;
length filename $200;
filename=cats("&target",_n_,'.json');
file out filevar=filename ;
sep = '[' ;
do i=1 to &n until (eof);
infile json2 end=eof;
input ;
put sep $1. _infile_;
sep=',';
end;
put ']';
run;
*Now that we have our correctly formated raw JSON file we can use the SAS json engine mapper to read in our JSON file and
output into SAS datasets.
The location real_map is the custom map we have created which assigns labels also. It outputs the data into two datasets of interest
1 - Evertything includes most of the information needed
2 - address_addressLines contains the address information
3 - A third dataset is created called all_data. This information is not needed but cannot be suppressed from being output so this can be deleted
afterwards;
filename json3 "\\location\data\data_set_.json"; * This location has all the smaller json files
libname json3 JSON fileref=json3;
filename real_map "location\full_json_map_with_labels.map";*/
libname json3 json fileref=json3 map=real_map;
proc copy in=json3 out=out_json memtype=data;
run;
*For efficiency we will put all the address information into one variable;
proc transpose data=out_json.address_addresslines out=addresses prefix=add_;
by ordinal_root ;
var addressLine;
run;
data address;
set addresses;
full_address=catx(',',add_1,add_2,add_3);
run;
*Join the address data with the other data which we will called data_of_interest e.g. this should create a replica of what appears in the json file i.e.
each payslip record in the json file will have the same record in the SAS file;
*Ordinal root is the linking key;
proc sql;
create table out_json.data_of_interest as select *
from
out_json.everything
full join
work.address
on everything.ordinal_root=address.ordinal_root;
quit;
So all this works fine, but basically I need to be able include it in a macro which will output these json files into a number of separate sas files.
Would anyone be able to provide any input?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.