I have a SAS code: %let input_string =%nrbquote([{"OrderID": "A0000123", "OrderDate": "4/30/2010"},{"OrderID": "A0000124", "OrderDate": ""}]);
data json_text;
json_text="&input_String.";
run;
data Parse_JSON (drop=json_text drop=regex01 drop=regex02 drop=regex03 drop=regex04);
set WORK.json_text;
retain
regex01
regex02
regex03
regex04
;
if _N_ = 1 then do;
regex01=prxparse("/(.+?)OrderID(.+?)OrderDate/");
regex02=prxparse("/(.+?)OrderDate(.+?)\}/");
regex03=prxparse("/(.+?)OrderID(.+?)OrderDate/");
regex04=prxparse("/(.+?)OrderDate(.+?)\}/");
end;
if prxmatch(regex01, json_text) then do;
OrderID1=strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex01, 2, json_text)),":",""),",",""),'"',""));
end;
if prxmatch(regex02, json_text) then do;
OrderDate1=input(strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex02, 2, json_text)),":",""),",",""),'"',"")),YYMMDD10.);
end;
if prxmatch(regex03, json_text) then do;
OrderID2=strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex03, 2, json_text)),":",""),",",""),'"',""));
end;
if prxmatch(regex04, json_text) then do;
OrderDate2=input(strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex04, 2, json_text)),":",""),",",""),'"',"")),YYMMDD10.);
end;
run; I want to get the output JSON table as OrderID1 OrderDate1 OrderID1 OrderDate1 A0000123 4/30/2010 A0000124 However, when I run it, I get OrderID1 OrderDate1 OrderID1 OrderDate1 A0000123 A0000123 How can I fix my code. Kindly help. Many many thanks.
... View more