<?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: Error in my macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-in-my-macro/m-p/823583#M325198</link>
    <description>&lt;P&gt;Can you provide some example input character strings with the date values you expect to create for those example strings?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the issue with the macro code?&amp;nbsp; Or the SAS code you are using the macro to generate?&amp;nbsp; Did you test the logic of the SAS code before wrapping it in a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro seems to work in the sense that executes without any errors and generates SAS code that does not have any obvious syntax errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bute the code it generates has some issues since it it treating the result of the SUBSTR() function call like it is a number and attempting to assign a numeric missing value to a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1977  options mprint;
1978  data test;
1979    string='12/12/2020';
1980    %datecharnum(number,string)
MPRINT(DATECHARNUM):   if string ne "" then do;
MPRINT(DATECHARNUM):   if find(string, "xx/xx")&amp;gt;0 then number = mdy(6, 1, substr(string, 7));
MPRINT(DATECHARNUM):   else if find(string, "xx")&amp;gt;0 then number = input(substr(string, 4), anydtdte.)+14;
MPRINT(DATECHARNUM):   * 15 of each month;
MPRINT(DATECHARNUM):   else number = input(string, DDMMYY10.);
MPRINT(DATECHARNUM):   end;
MPRINT(DATECHARNUM):   else do;
MPRINT(DATECHARNUM):   string = .;
MPRINT(DATECHARNUM):   end;
MPRINT(DATECHARNUM):   format number DDMMYY10.;
1981    put (_all_) (=);
1982  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      1:97
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      2:79
string=12/12/2020 number=12/12/2020
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jul 2022 21:02:46 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-07-15T21:02:46Z</dc:date>
    <item>
      <title>Error in my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-my-macro/m-p/823579#M325195</link>
      <description>&lt;P&gt;Please, need an assitance for this macro below, It doesn't work. I don't know why!&lt;/P&gt;
&lt;P&gt;The aim is to alter a date character to a date numeric. Sometime, I could not I have the day of character date. So, the reference is XXday=15&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro DateCharNum(VarNum, VarChar);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if &amp;amp;VarChar. ne "" then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if find(&amp;amp;VarChar., "xx/xx")&amp;gt;0 then &amp;amp;VarNum. = mdy(6, 1, substr(&amp;amp;VarChar., 7));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if find(&amp;amp;VarChar., "xx")&amp;gt;0 then &amp;amp;VarNum. = input(substr(&amp;amp;VarChar., 4), anydtdte.)+14; * 15 of each month;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else &amp;amp;VarNum. = input(&amp;amp;VarChar., DDMMYY10.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do; &amp;nbsp;&amp;amp;VarChar. = .;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format &amp;amp;VarNum. DDMMYY10.;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 20:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-my-macro/m-p/823579#M325195</guid>
      <dc:creator>CorinneT</dc:creator>
      <dc:date>2022-07-15T20:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: Error in my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-my-macro/m-p/823582#M325197</link>
      <description>&lt;P&gt;Really should provide some example values of the input and the desired output value.&lt;/P&gt;
&lt;P&gt;Doesn't work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages. If macros are involved set OPTIONS MPRINT; prior to executing the code so the macro resolution is shown.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to consider the COALESCE function in the MDY function. Pull the year, month and day from the string.&lt;/P&gt;
&lt;P&gt;then use Coalesce with possible missing&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;date = mdy(6,coalesce(numday,15),2015);&lt;/P&gt;
&lt;P&gt;for example if the numday is missing return 06/15/2015 (in mmddyy ) or 06/numday/2015 if a day valid for the month.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 21:01:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-my-macro/m-p/823582#M325197</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-15T21:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error in my macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-my-macro/m-p/823583#M325198</link>
      <description>&lt;P&gt;Can you provide some example input character strings with the date values you expect to create for those example strings?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the issue with the macro code?&amp;nbsp; Or the SAS code you are using the macro to generate?&amp;nbsp; Did you test the logic of the SAS code before wrapping it in a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro seems to work in the sense that executes without any errors and generates SAS code that does not have any obvious syntax errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bute the code it generates has some issues since it it treating the result of the SUBSTR() function call like it is a number and attempting to assign a numeric missing value to a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1977  options mprint;
1978  data test;
1979    string='12/12/2020';
1980    %datecharnum(number,string)
MPRINT(DATECHARNUM):   if string ne "" then do;
MPRINT(DATECHARNUM):   if find(string, "xx/xx")&amp;gt;0 then number = mdy(6, 1, substr(string, 7));
MPRINT(DATECHARNUM):   else if find(string, "xx")&amp;gt;0 then number = input(substr(string, 4), anydtdte.)+14;
MPRINT(DATECHARNUM):   * 15 of each month;
MPRINT(DATECHARNUM):   else number = input(string, DDMMYY10.);
MPRINT(DATECHARNUM):   end;
MPRINT(DATECHARNUM):   else do;
MPRINT(DATECHARNUM):   string = .;
MPRINT(DATECHARNUM):   end;
MPRINT(DATECHARNUM):   format number DDMMYY10.;
1981    put (_all_) (=);
1982  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      1:97
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      2:79
string=12/12/2020 number=12/12/2020
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 21:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-my-macro/m-p/823583#M325198</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-15T21:02:46Z</dc:date>
    </item>
  </channel>
</rss>

