Hi Instructures,
The code below are insensitive whether the input to the DOB has the wrong formate or empty. I want to create two macros: &EmptyDT. , &WrongDT. for later use to trigger error messages. How can I do that?
%let input_string =%nrbquote([{"MEMBERID": "A123456", "DOB": "2022-03-02"}]);
data json_text;
json_text="&input_String.";
run;
data Parse_JSON (drop=json_text drop=regex01 drop=regex02);
set WORK.json_text;
retain
regex01
regex02
;
if _N_ = 1 then do;
regex01=prxparse("/(.+?)MEMBERID(.+?)DOB/");
regex02=prxparse("/(.+?)DOB(.+?)\}/");
end;
if prxmatch(regex01, json_text) then do;
MEMBERID=strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex01, 2, json_text)),":",""),",",""),'"',""));
end;
if prxmatch(regex02, json_text) then do;
DOB=input(strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex02, 2, json_text)),":",""),",",""),'"',"")),YYMMDD10.);
end;
run;
proc sql noprint;
/*Assign Macro vars to Params for ERRmsg*/
select compress("'"||%nrquote(MEMBERID)||"'") into: MEMBERID from Parse_JSON;
select
case when MEMBERID in ("",".") then 1
else 0 end into: inv_MEMBERID_ind from Parse_JSON;
select DOB as DoB_ format=yymmddd10. informat=yymmddd10. into: DOB from Parse_JSON;
select
case when DOB ne . then 1
else 0 end into: DOB_IND from Parse_JSON;
quit;
Kindly help!
Thanks
... View more