<?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: What is wrong with the this marco code for imputing date and time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876761#M346360</link>
    <description>&lt;P&gt;Step 1: get rid of all the macro code and create a DATA step which does it for a single variable in a single dataset.&lt;/P&gt;
&lt;P&gt;Since you only want the dataset and variable names to be dynamic,&amp;nbsp;&lt;STRONG&gt;only those&lt;/STRONG&gt; need to be replaced by macro parameters. There is absolutely NO need to use %IF anywhere.&lt;/P&gt;</description>
    <pubDate>Sat, 20 May 2023 13:52:51 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-05-20T13:52:51Z</dc:date>
    <item>
      <title>What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876752#M346357</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; When run the following code for imputing the date and time, I am getting the following errors. Can anyone help me what is wrong with this? Also, I do not understand why prxid variable value is showing different values whenever I execute the call statement&amp;nbsp;%splitIso8601dtc( inDat= ae, outDat= ksfe_2018, var= aestdtc ).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me to understand what is wrong with the code and how correct it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Errors are:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Invalid regular expression delimiter "p" in "prxid". Delimiter must be non-alphanumeric&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;and non-whitespace.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: The regular expression passed to the function PRXMATCH contains a syntax error.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;WARNING: Argument 1 to function PRXMATCH referenced by the %SYSFUNC or %QSYSFUNC macro function&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;is out of range.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;result of the operations have been set to a missing value.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;operand is required. The condition was: %sysfunc(prxmatch(prxid,&amp;amp;var))&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: The macro SPLITISO8601DTC will stop executing.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;U&gt;&lt;STRONG&gt;Sample data set for testing the code:&lt;/STRONG&gt;&lt;/U&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;DATA ae;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;length aestdtc $ 20.;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;aestdtc= '2017-03'; OUTPUT;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;aestdtc= '2017-03-01T14'; OUTPUT;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;aestdtc= '2017---15'; OUTPUT;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;aestdtc= '2017-03--T07:30'; OUTPUT;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;aestdtc= '2017----T07:30'; OUTPUT;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;RUN;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;proc print;run;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;U&gt;&lt;STRONG&gt;Macro code is follows:&lt;/STRONG&gt;&lt;/U&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;%MACRO splitIso8601dtc( inDat= , outDat= , var= ) / DES='Macro to separate ISO 8601 datetime components';&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;DATA &amp;amp;outDat;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;SET &amp;amp;inDat;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* create regular expression ID to separate is8601dt datetime components;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%let prxid= %sysfunc(prxparse('/^(\d{4})(-(\d{2}|-)(-(\d{2}|-)(T(\d{2}|-)(:(\d{2}|-)(:(\d{2}))?)?)?)?)?\s*$/'));&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%put var is.............&amp;amp;var;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%put prxid is ...........&amp;amp;prxid;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%IF %sysfunc(prxmatch(prxid,&amp;amp;var)) %THEN %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* separate datetime components;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._year= input(compress(%sysfunc(prxposn(prxid,1,&amp;amp;var),'-')), 4.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_month= input(compress(%sysfunc(prxposn(prxid,3,&amp;amp;var),'-')), 2.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_day= input(compress(%sysfunc(prxposn(prxid,5,&amp;amp;var),'-')), 2.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_hour= input(compress(%sysfunc(prxposn(prxid,7,&amp;amp;var),'-')), 2.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_minute= input(compress(%sysfunc(prxposn(prxid,9,&amp;amp;var),'-')), 2.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_second= input(compress(%sysfunc(prxposn(prxid,11,&amp;amp;var),'-')), 2.);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* impute missing datetime components;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* impute month when missing;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%IF missing(&amp;amp;var._min_month) %THEN %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_month= 1;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_month= 12;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%ELSE %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_month= &amp;amp;var._min_month;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* impute day when missing;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%IF missing(&amp;amp;var._min_day) %THEN %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_day= 1;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* Last day of the respective month and year;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_day= day(intnx('month',input(cats(put(&amp;amp;var._year,z4.),'-'&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;,put(&amp;amp;var._max_month,z2.),'-01')&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;,is8601da.)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;,0&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;,'E'));&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%ELSE %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_day= &amp;amp;var._min_day;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* impute hour when missing;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%IF missing(&amp;amp;var._min_hour) %THEN %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_hour= 0;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_hour= 23;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%ELSE %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_hour= &amp;amp;var._min_hour;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* impute minute when missing;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%IF missing(&amp;amp;var._min_minute) %THEN %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_minute= 0;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_minute= 59;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%ELSE %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_minute= &amp;amp;var._min_minute;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* impute second when missing;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%IF missing(&amp;amp;var._min_second) %THEN %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min_second= 0;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_second= 59;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%ELSE %DO;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max_second= &amp;amp;var._min_second;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;%END;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;* create the full date/time value;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;FORMAT &amp;amp;var._min &amp;amp;var._max is8601dt.;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._min= dhms(mdy(&amp;amp;var._min_month, &amp;amp;var._min_day, &amp;amp;var._year)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;,&amp;amp;var._min_hour, &amp;amp;var._min_minute, &amp;amp;var._min_second);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;&amp;amp;var._max= dhms(mdy(&amp;amp;var._max_month, &amp;amp;var._max_day, &amp;amp;var._year)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;,&amp;amp;var._max_hour, &amp;amp;var._max_minute, &amp;amp;var._max_second);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;&amp;nbsp; &amp;nbsp; %END;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;%MEND splitIso8601dtc;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;U&gt;&lt;STRONG&gt;Calling the above marco:&lt;/STRONG&gt;&lt;/U&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;%splitIso8601dtc( inDat= ae, outDat= ksfe_2018, var= aestdtc )&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks&lt;/DIV&gt;</description>
      <pubDate>Sat, 20 May 2023 13:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876752#M346357</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-05-20T13:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876753#M346358</link>
      <description>&lt;P&gt;Too many pieces to this that I don't understand.&amp;nbsp; But the one I do understand is this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro language %IF %THEN statements do not execute for every observation in a SAS data set.&amp;nbsp; They merely generate DATA step code.&amp;nbsp; So this statement can't work as intended:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF missing(&amp;amp;var._min_day) %THEN %DO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Even adding %SYSFUNC around the MISSING function won't help.&amp;nbsp; You would need to convert to DATA step IF THEN statements instead.&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 13:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876753#M346358</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-05-20T13:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876760#M346359</link>
      <description>&lt;P&gt;For debugging can eliminate the part of the macro after the PRXMATCH command, let's say eliminate code after the &lt;FONT face="courier new,courier" color="#0000FF"&gt;&lt;SPAN&gt;* impute missing datetime components;&lt;/SPAN&gt;&lt;/FONT&gt; comment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then since you have errors in the log, show us the ENTIRE log for this abbreviated macro. Do not shows us only the errors. Do not pick and choose parts of the log to show us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you have errors in a macro, you need run the macro debugging command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then re-run the macro and show us the ENTIRE log. Please copy and paste the log into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66123iA4EF494F9CA0F6EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 13:53:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876760#M346359</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-05-20T13:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876761#M346360</link>
      <description>&lt;P&gt;Step 1: get rid of all the macro code and create a DATA step which does it for a single variable in a single dataset.&lt;/P&gt;
&lt;P&gt;Since you only want the dataset and variable names to be dynamic,&amp;nbsp;&lt;STRONG&gt;only those&lt;/STRONG&gt; need to be replaced by macro parameters. There is absolutely NO need to use %IF anywhere.&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 13:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876761#M346360</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-05-20T13:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876762#M346361</link>
      <description>&lt;P&gt;Hi PaigeMiller, I have edited my earlier reply with the mprint option as after re-opening the SAS, I missed to run the code to create the dataset. Now, I have run it and here are the errors in the log with mprint:&lt;/P&gt;&lt;P&gt;options mprint;&lt;BR /&gt;96&lt;BR /&gt;97 %splitIso8601dtc( inDat= ae, outDat= ksfe_2018, var= aestdtc )&lt;BR /&gt;MPRINT(SPLITISO8601DTC): DATA ksfe_2018;&lt;BR /&gt;MPRINT(SPLITISO8601DTC): SET ae;&lt;BR /&gt;MPRINT(SPLITISO8601DTC): * create regular expression ID to separate is8601dt datetime&lt;BR /&gt;components;&lt;BR /&gt;var is.............aestdtc&lt;BR /&gt;prxid is ...........1&lt;BR /&gt;ERROR: Invalid regular expression delimiter "p" in "prxid". Delimiter must be non-alphanumeric&lt;BR /&gt;and non-whitespace.&lt;BR /&gt;ERROR: The regular expression passed to the function PRXMATCH contains a syntax error.&lt;BR /&gt;WARNING: Argument 1 to function PRXMATCH referenced by the %SYSFUNC or %QSYSFUNC macro function&lt;BR /&gt;is out of range.&lt;BR /&gt;NOTE: Mathematical operations could not be performed during %SYSFUNC function execution. The&lt;BR /&gt;result of the operations have been set to a missing value.&lt;BR /&gt;ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric&lt;BR /&gt;operand is required. The condition was: %sysfunc(prxmatch(prxid,&amp;amp;var))&lt;BR /&gt;ERROR: The macro SPLITISO8601DTC will stop executing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 14:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876762#M346361</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-05-20T14:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876763#M346362</link>
      <description>&lt;P&gt;You are trying to use macro code to work with data.&amp;nbsp; That cannot work.&amp;nbsp; You use the macro processor to generate SAS code.&amp;nbsp; It is the job of the SAS code the macro generates to work with the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So this statement should not be using macro code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let prxid= %sysfunc(prxparse('/^(\d{4})(-(\d{2}|-)(-(\d{2}|-)(T(\d{2}|-)(:(\d{2}|-)(:(\d{2}))?)?)?)?)?\s*$/'));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the reason it is getting an error is because you included quotes where they are not needed.&amp;nbsp; So those because part of the string you passed to PRXPARSE().&amp;nbsp; So it sees the single quote character as the first character so it uses that as the separator instead of the normal / character.&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 15:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876763#M346362</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-20T15:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876764#M346363</link>
      <description>&lt;P&gt;DO NOT use MACRO code where you need SAS code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro splitIso8601dtc
(inDat=    /* Input dataset name */
,outDat=   /* Output dataset name */
,var=      /* Input characer variable name */
) / DES='Macro to separate ISO 8601 datetime components';

%local pattern ;
%let pattern = /^(\d{4})(-(\d{2}|-)(-(\d{2}|-)(T(\d{2}|-)(:(\d{2}|-)(:(\d{2}))?)?)?)?)?\s*$/;
%put NOTE: &amp;amp;sysmacroname: &amp;amp;=indat &amp;amp;=outdat &amp;amp;=var &amp;amp;=pattern;

* create new dataset from existing dataset ;
DATA &amp;amp;outDat;
  SET &amp;amp;inDat;
 
* create regular expression ID to separate is8601dt datetime components;
  if _n_=1 then prxid= prxparse("&amp;amp;pattern");
  retain prxid ;
 
* separate datetime components;
  if prxmatch(prxid,&amp;amp;var) then do; 
    &amp;amp;var._year= input(prxposn(prxid,1,&amp;amp;var), ??4.);
    &amp;amp;var._min_month= input(prxposn(prxid,3,&amp;amp;var), ??2.);
    &amp;amp;var._min_day= input(prxposn(prxid,5,&amp;amp;var), ??2.);
    &amp;amp;var._min_hour= input(prxposn(prxid,7,&amp;amp;var), ??2.);
    &amp;amp;var._min_minute= input(prxposn(prxid,9,&amp;amp;var), ??2.);
    &amp;amp;var._min_second= input(prxposn(prxid,11,&amp;amp;var), ??2.);
 
* impute missing datetime components;
* impute month when missing;
    if missing(&amp;amp;var._min_month) then do;
      &amp;amp;var._min_month= 1;
      &amp;amp;var._max_month= 12;
    end;
    else do; 
      &amp;amp;var._max_month= &amp;amp;var._min_month;
    end;

* impute day when missing;
    if missing(&amp;amp;var._min_day) then do;
      &amp;amp;var._min_day= 1;
* Last day of the respective month and year;
      &amp;amp;var._max_day=day(intnx('month',mdy(&amp;amp;var._max_month,1,&amp;amp;var._year),0,'E'));
    end;
    else do;
      &amp;amp;var._max_day= &amp;amp;var._min_day;
    end;
 
* impute hour when missing;
    if missing(&amp;amp;var._min_hour) then do;
      &amp;amp;var._min_hour= 0;
      &amp;amp;var._max_hour= 23;
    end;
    else do;
      &amp;amp;var._max_hour= &amp;amp;var._min_hour;
    end;
 
* impute minute when missing;
    if missing(&amp;amp;var._min_minute) then do;
      &amp;amp;var._min_minute= 0;
      &amp;amp;var._max_minute= 59;
    end;
    else do;
      &amp;amp;var._max_minute= &amp;amp;var._min_minute;
    end;
 
* impute second when missing;
    IF missing(&amp;amp;var._min_second) then do;
      &amp;amp;var._min_second= 0;
      &amp;amp;var._max_second= 59;
    end;
    else do;
      &amp;amp;var._max_second= &amp;amp;var._min_second;
    end;
 
* create the full date/time value;
    &amp;amp;var._min= dhms(mdy(&amp;amp;var._min_month, &amp;amp;var._min_day, &amp;amp;var._year)
                   ,&amp;amp;var._min_hour, &amp;amp;var._min_minute, &amp;amp;var._min_second)
    ;
    &amp;amp;var._max= dhms(datepart(&amp;amp;var._min)
              ,&amp;amp;var._max_hour, &amp;amp;var._max_minute, &amp;amp;var._max_second)
    ;
  end;
  FORMAT &amp;amp;var._min &amp;amp;var._max is8601dt.;
run;

%MEND splitIso8601dtc;

* Sample data ;
data ae;
  length aestdtc $20;
  input aestdtc ;
datalines;
2017-03
2017-03-01T14
2017---15
2017-03--T07:30
2017----T07:30
;

 
* call the macro ;
options mprint;
%splitIso8601dtc( inDat= ae, outDat= ksfe_2018, var= aestdtc )

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 May 2023 17:41:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876764#M346363</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-20T17:41:03Z</dc:date>
    </item>
    <item>
      <title>Re: What is wrong with the this marco code for imputing date and time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876765#M346364</link>
      <description>&lt;P&gt;Thank you very much Tom. It's working now. It helped me a lot.&amp;nbsp; Now, I understand what went wrong with the code.&amp;nbsp;Once again, thank you very much.&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2023 16:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-wrong-with-the-this-marco-code-for-imputing-date-and/m-p/876765#M346364</guid>
      <dc:creator>Moksha</dc:creator>
      <dc:date>2023-05-20T16:38:31Z</dc:date>
    </item>
  </channel>
</rss>

