<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Wrong text pattern caught in the input date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800573#M314976</link>
    <description>&lt;P&gt;I've correct the code for the subscripts 1, and 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mlogic mlogicnest mprint;
%let input_string =%nrbquote([{"MEMBERID1": "A12345687", "DOB1": "unknown", "MEMBERID2": "A12345677", "DOB2": "2022-01-03"}]);

filename json temp;
data json_str;
  file json;
  length string $32767;
  string=symget('input_string');
  put string ;
run;

libname json json fileref=json;

proc print data=json.root (drop=ordinal:) noobs;
run;


data _null_;
  set json_str;
  call symputx('memberid1',quote(trim(memberid1),"'"));
  call symputx('dob1',dob1);
  if strip(dob1) in (' ' '.') then dob1_ind=0;
  else if not missing(input(dob1,??yymmdd10.)) then dob1_ind=1;
  else dob1_ind=2;
  call symputx('dob1_ind',dob1_ind);

  call symputx('memberid2',quote(trim(memberid2),"'"));
  call symputx('dob2',dob2);
  if strip(dob2) in (' ' '.') then dob2_ind=0;
  else if not missing(input(dob2,??yymmdd10.)) then dob2_ind=1;
  else dob2_ind=2;
  call symputx('dob2_ind',dob2_ind);
run;


%put &amp;amp;=memberid1;
%put &amp;amp;=dob1;
%put &amp;amp;=dob1_ind;
%put &amp;amp;=memberid2;
%put &amp;amp;=dob2;
%put &amp;amp;=dob2_ind;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;here is the log,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
SYMBOLGEN:  Macro variable MEMBERID1 resolves to '           .'
59         
60         
61         %put &amp;amp;=memberid1;
MEMBERID1='           .'
62         %put &amp;amp;=dob1;
SYMBOLGEN:  Macro variable DOB1 resolves to .
DOB1=.
63         %put &amp;amp;=dob1_ind;
SYMBOLGEN:  Macro variable DOB1_IND resolves to 0
DOB1_IND=0
64         %put &amp;amp;=memberid2;
3                                                          The SAS System                                09:32 Monday, March 7, 2022

SYMBOLGEN:  Macro variable MEMBERID2 resolves to '           .'
MEMBERID2='           .'
65         %put &amp;amp;=dob2;
SYMBOLGEN:  Macro variable DOB2 resolves to .
DOB2=.
66         %put &amp;amp;=dob2_ind;
SYMBOLGEN:  Macro variable DOB2_IND resolves to 0
DOB2_IND=0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;how can I capture the values for these inputs?&lt;/P&gt;
&lt;P&gt;The &lt;CODE class=" language-sas"&gt;Macro variable DOB1,&lt;/CODE&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;Macro variable DOB2&lt;/CODE&gt;,&amp;nbsp;&lt;CODE class=" language-sas"&gt;Macro variable DOB1_IND&lt;/CODE&gt;,&lt;CODE class=" language-sas"&gt;Macro variable DOB2_IND&lt;/CODE&gt;&amp;nbsp;do not resolve correctly here.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Mar 2022 07:01:19 GMT</pubDate>
    <dc:creator>sarahzhou</dc:creator>
    <dc:date>2022-03-07T07:01:19Z</dc:date>
    <item>
      <title>Wrong text pattern caught in the input date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800544#M314956</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to resolve both date of birth (DOB) for two members, MEMBERID1 and MEMBERID2. I need the DOB1 AND DOB2 can be caught eighter its empty input, correct date fomate input, or wrong date formate input. It works fines with only one member, and now has a bug.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let input_string =%nrbquote([{"MEMBERID1": "A12345690", "DOB1": "2022-02-03", "MEMBERID2": "A12345677", "DOB2": "2022-01-03"}]);

data json_text;
json_text="&amp;amp;input_String.";
run;

data Parse_JSON_OID (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("/(.+?)MEMBERID1(.+?)DOB1/"); 
		regex02=prxparse("/(.+?)DOB1(.+?)\}/"); 
        regex03=prxparse("/(.+?)MEMBERID2(.+?)DOB2/"); 
		regex04=prxparse("/(.+?)DOB2(.+?)\}/"); 
	end;
	if prxmatch(regex01, json_text) then do;
		MEMBERID1=strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex01, 2, json_text)),":",""),",",""),'"',""));
    end;

	if prxmatch(regex02, json_text) then do;
		DOB1=strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex02, 2, json_text)),":",""),",",""),'"',""));
    end;

	if prxmatch(regex03, json_text) then do;
		MEMBERID2=strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex03, 2, json_text)),":",""),",",""),'"',""));
    end;
	if prxmatch(regex04, json_text) then do;
		DOB2=strip(tranwrd(tranwrd(tranwrd(upcase(prxposn(regex04, 2, json_text)),":",""),",",""),'"',""));
    end;run;



data _null_;
  set Parse_JSON_OID;
  call symputx('MEMBERID1',quote(trim(MEMBERID1),"'"));
  call symputx('DOB1',DOB1);
  if strip(DOB1) in (' ' '.') then dob1_ind=0;
  else if not missing(input(DOB1,??yymmdd10.)) then dob1_ind=1;
  else dob1_ind=2;
  call symputx('dob1_ind',dob1_ind);

  call symputx('MEMBERID2',quote(trim(MEMBERID2),"'"));
  call symputx('DOB2',DOB2);
  if strip(DOB2) in (' ' '.') then dob2_ind=0;
  else if not missing(input(DOB2,??yymmdd10.)) then dob2_ind=1;
  else dob2_ind=2;
  call symputx('dob2_ind',dob2_ind);
run;

%put &amp;amp;=MEMBERID1;
%put &amp;amp;=MEMBERID2;
%put &amp;amp;=dob1;
%put &amp;amp;=dob2;
%put &amp;amp;=dob1_ind;
%put &amp;amp;=dob2_ind;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarahzhou_0-1646626216999.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69197i9C2A76D09A00A263/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarahzhou_0-1646626216999.png" alt="sarahzhou_0-1646626216999.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The DOB1 is catching a wrong string &lt;CODE class=" language-sas"&gt; Macro variable DOB1 resolves to 2022-02-03 MEMBERID2 A12345677 DOB2 2022-01-03.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;How can I fix this?&lt;/P&gt;
&lt;P&gt;I want&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;DOB1 resolves to&amp;nbsp;2022-02-03&lt;/CODE&gt;, &lt;CODE class=" language-sas"&gt;Macro variable DOB1_IND resolves to 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;DOB2 resolves to 2022-01-03&lt;/CODE&gt;, &lt;CODE class=" language-sas"&gt;Macro variable DOB1_IND resolves to 1&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;in this input. If the BOB1 is empty then, it should give&amp;nbsp;&lt;CODE class=" language-sas"&gt;Macro variable DOB1_IND resolves to 0&lt;/CODE&gt;. according the if else conditiong in above code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;(Also thanks for the folks who helped in the old code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 04:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800544#M314956</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-03-07T04:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong text pattern caught in the input date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800550#M314960</link>
      <description>&lt;P&gt;Your description of the problem does not seem to match the issue.&lt;/P&gt;
&lt;P&gt;The issue is your pattern for DOB1 is extracting more of the string.&lt;/P&gt;
&lt;P&gt;It does not really matter to you date test since you just used the first 10 bytes of the string.&amp;nbsp; But if you tried to use the macro variable as a date it would not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why aren't you using the solution on the other threads that use the JSON libref engine to parse the JSON string?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 05:41:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800550#M314960</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-07T05:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong text pattern caught in the input date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800557#M314964</link>
      <description>&lt;P&gt;&lt;EM&gt;Why aren't you using the solution on the other threads that use the JSON libref engine to parse the JSON string?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I tried,&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mlogic mlogicnest mprint;
%let input_string =%nrbquote([{"MEMBERID1": "A12345690", "DOB1": "unknown", "MEMBERID2": "A12345677", "DOB2": "2022-01-03"}]);

filename json temp;
data json_str;
  file json;
  length string $32767;
  string=symget('input_string');
  put string ;
run;

libname json json fileref=json;

proc print data=json.root (drop=ordinal:) noobs;
run;


data _null_;
  set json_str;
  call symputx('memberid1',quote(trim(memberid1),"'"));
  call symputx('dob1',dob1);
  if strip(dob1) in (' ' '.') then dob1_ind=0;
  else if not missing(input(dob1,??yymmdd10.)) then dob1_ind=1;
  else dob1_ind=2;
  call symputx('dob1_ind',dob_ind);
  call symputx('memberid1',quote(trim(memberid1),"'"));
  call symputx('dob1',dob1);
  if strip(dob1) in (' ' '.') then dob1_ind=0;
  else if not missing(input(dob1,??yymmdd10.)) then dob1_ind=1;
  else dob1_ind=2;
  call symputx('dob1_ind',dob_ind);
run;


%put &amp;amp;=memberid1;
%put &amp;amp;=dob1;
%put &amp;amp;=dob1_ind;
%put &amp;amp;=memberid2;
%put &amp;amp;=dob2;
%put &amp;amp;=dob2_ind;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but this gives&amp;nbsp;&lt;CODE class=" language-sas"&gt;dob1_ind&lt;/CODE&gt;&amp;nbsp;and&amp;nbsp;&lt;CODE class=" language-sas"&gt;dob2_ind&lt;/CODE&gt;&amp;nbsp;incorrect,&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;62         %put &amp;amp;=dob1_ind;
SYMBOLGEN:  Macro variable DOB1_IND resolves to .
DOB1_IND=.
63         %put &amp;amp;=memberid2;
SYMBOLGEN:  Macro variable MEMBERID2 resolves to 'A12345677'
MEMBERID2='A12345677'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SYMBOLGEN:  Macro variable DOB1_IND resolves to 2&lt;/CODE&gt;&amp;nbsp;if &lt;CODE class=" language-sas"&gt;"DOB1": "unknown"&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;SYMBOLGEN:  Macro variable DOB2_IND resolves to 1&lt;/CODE&gt;&amp;nbsp;if &amp;nbsp;&lt;CODE class=" language-sas"&gt;DOB2": "2022-01-03"&lt;/CODE&gt;. Acording to our code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 06:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800557#M314964</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-03-07T06:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong text pattern caught in the input date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800558#M314965</link>
      <description>&lt;P&gt;Here is the log,&lt;/P&gt;
&lt;PRE&gt;SYMBOLGEN:  Macro variable MEMBERID1 resolves to '           .'
58         
59         
60         %put &amp;amp;=memberid1;
MEMBERID1='           .'
61         %put &amp;amp;=dob1;
SYMBOLGEN:  Macro variable DOB1 resolves to .
DOB1=.
62         %put &amp;amp;=dob1_ind;
SYMBOLGEN:  Macro variable DOB1_IND resolves to .
DOB1_IND=.
63         %put &amp;amp;=memberid2;
SYMBOLGEN:  Macro variable MEMBERID2 resolves to 'A12345677'
MEMBERID2='A12345677'
3                                                          The SAS System                                09:32 Monday, March 7, 2022

64         %put &amp;amp;=dob2;
SYMBOLGEN:  Macro variable DOB2 resolves to 2022-01-03
DOB2=2022-01-03
65         %put &amp;amp;=dob2_ind;
SYMBOLGEN:  Macro variable DOB2_IND resolves to 1
DOB2_IND=1&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Mar 2022 06:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800558#M314965</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-03-07T06:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong text pattern caught in the input date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800559#M314966</link>
      <description>&lt;P&gt;Why aren't you using the same data that you printed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=&lt;STRONG&gt;json.root&lt;/STRONG&gt; (drop=ordinal:) noobs;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 06:11:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800559#M314966</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-07T06:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong text pattern caught in the input date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800564#M314968</link>
      <description>&lt;P&gt;The output data is,&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sarahzhou_0-1646633644829.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69202iB8A4107CDA918E73/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sarahzhou_0-1646633644829.png" alt="sarahzhou_0-1646633644829.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;How can I use DOB1 and DOB2, and assige them the &amp;amp;DOB1_IND,&amp;nbsp;&amp;amp;DOB2_IND;&lt;/P&gt;
&lt;P&gt;they should have assigned like this in our case&lt;/P&gt;
&lt;PRE&gt;SYMBOLGEN:  Macro variable DOB1_IND resolves to 2
DOB1_IND=2&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SYMBOLGEN:  Macro variable DOB2_IND resolves to 1
DOB2_IND=1&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Mar 2022 06:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800564#M314968</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-03-07T06:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong text pattern caught in the input date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800573#M314976</link>
      <description>&lt;P&gt;I've correct the code for the subscripts 1, and 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen mlogic mlogicnest mprint;
%let input_string =%nrbquote([{"MEMBERID1": "A12345687", "DOB1": "unknown", "MEMBERID2": "A12345677", "DOB2": "2022-01-03"}]);

filename json temp;
data json_str;
  file json;
  length string $32767;
  string=symget('input_string');
  put string ;
run;

libname json json fileref=json;

proc print data=json.root (drop=ordinal:) noobs;
run;


data _null_;
  set json_str;
  call symputx('memberid1',quote(trim(memberid1),"'"));
  call symputx('dob1',dob1);
  if strip(dob1) in (' ' '.') then dob1_ind=0;
  else if not missing(input(dob1,??yymmdd10.)) then dob1_ind=1;
  else dob1_ind=2;
  call symputx('dob1_ind',dob1_ind);

  call symputx('memberid2',quote(trim(memberid2),"'"));
  call symputx('dob2',dob2);
  if strip(dob2) in (' ' '.') then dob2_ind=0;
  else if not missing(input(dob2,??yymmdd10.)) then dob2_ind=1;
  else dob2_ind=2;
  call symputx('dob2_ind',dob2_ind);
run;


%put &amp;amp;=memberid1;
%put &amp;amp;=dob1;
%put &amp;amp;=dob1_ind;
%put &amp;amp;=memberid2;
%put &amp;amp;=dob2;
%put &amp;amp;=dob2_ind;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;here is the log,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
SYMBOLGEN:  Macro variable MEMBERID1 resolves to '           .'
59         
60         
61         %put &amp;amp;=memberid1;
MEMBERID1='           .'
62         %put &amp;amp;=dob1;
SYMBOLGEN:  Macro variable DOB1 resolves to .
DOB1=.
63         %put &amp;amp;=dob1_ind;
SYMBOLGEN:  Macro variable DOB1_IND resolves to 0
DOB1_IND=0
64         %put &amp;amp;=memberid2;
3                                                          The SAS System                                09:32 Monday, March 7, 2022

SYMBOLGEN:  Macro variable MEMBERID2 resolves to '           .'
MEMBERID2='           .'
65         %put &amp;amp;=dob2;
SYMBOLGEN:  Macro variable DOB2 resolves to .
DOB2=.
66         %put &amp;amp;=dob2_ind;
SYMBOLGEN:  Macro variable DOB2_IND resolves to 0
DOB2_IND=0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;how can I capture the values for these inputs?&lt;/P&gt;
&lt;P&gt;The &lt;CODE class=" language-sas"&gt;Macro variable DOB1,&lt;/CODE&gt;&amp;nbsp;&lt;CODE class=" language-sas"&gt;Macro variable DOB2&lt;/CODE&gt;,&amp;nbsp;&lt;CODE class=" language-sas"&gt;Macro variable DOB1_IND&lt;/CODE&gt;,&lt;CODE class=" language-sas"&gt;Macro variable DOB2_IND&lt;/CODE&gt;&amp;nbsp;do not resolve correctly here.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 07:01:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Wrong-text-pattern-caught-in-the-input-date-format/m-p/800573#M314976</guid>
      <dc:creator>sarahzhou</dc:creator>
      <dc:date>2022-03-07T07:01:19Z</dc:date>
    </item>
  </channel>
</rss>

