Hi, I'm pretty new to SAS and not sure if we can achieve it, but i try to generate a json form a table. Let say I get this dataset : data testdataset;
input sku$ label$ search__XX$ search__YY$ enabled;
datalines;
123-456 productA producAX productAY 1
123-789 productB producBX productBY 0
456-789 productC producCX productCY 1
; I want to transform it to {"identifier":"123-456","values":{"label":[{"scope":null,"data":"productA"}],"search":[{"scope":"XX","data":"producAX"},{"scope":"YY","data":"productAY"}],"enabled":[{"scope":null,"data":true}]}}
{"identifier":"123-789","values":{"label":[{"scope":null,"data":"productB"}],"search":[{"scope":"XX","data":"producBX"},{"scope":"YY","data":"productBY"}],"enabled":[{"scope":null,"data":false}]}}
{"identifier":"456-789","values":{"label":[{"scope":null,"data":"productC"}],"search":[{"scope":"XX","data":"producCX"},{"scope":"YY","data":"productCY"}],"enabled":[{"scope":null,"data":true}]}} I try do understand the doc of proc json but when i try something like proc json out="&ftpit\jsontest.json" pretty nosastags;
export testdataset;
run; I got extra array [ ] on my json, and also a comma between each items and i'm struggle to "split" my columns inside the "value" tag, but also be able to put specific column inside the right value Literraly i think i need to do something like a loop for each row of my dataset and -create json - create key idendifier and put testdataset.sku -create key values - create key label and put [{"scope":null,"data":testdataset.label}] - put coma - create key search and put [{"scope":"XX","data":testdataset.search__XX},{"scope":"YY","data":testdataset.search__YY}] - put coma - create key "enabled" and put [{"scope":null,"data": case when testdataset.enabled = 1 then true else false }] - close json not sure if it's something doable via sas ? Thanks for your help
... View more