<?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: Convert text to date in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578405#M164038</link>
    <description>&lt;P&gt;Hi Smuel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error message I get when I run this line of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let MonthEnd = %sysfunc(intnx(month,input(cats(&amp;amp;filedate.,01),yymmdd8.),0,E),date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Required operator not found in expression: input(cats(201906,01),yymmdd8.)&lt;BR /&gt;ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC&lt;BR /&gt;or %QSYSFUNC function reference is terminated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand what it means and I've tried many different variations.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Aug 2019 13:52:03 GMT</pubDate>
    <dc:creator>Stats10</dc:creator>
    <dc:date>2019-08-01T13:52:03Z</dc:date>
    <item>
      <title>Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578389#M164031</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got a macro that the user can define and it will always be in this format (YYYYMM) e.g.&lt;/P&gt;&lt;P&gt;%let filedate = 201906;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want another macro that will use this filedate and give me the last day of that month using something like this:&lt;/P&gt;&lt;P&gt;%let MonthEnd = %sysfunc(intnx(month,input(cats(&amp;amp;filedate.,01),yymmdd8.),0,E),date9.);&amp;nbsp; (&amp;lt;-- but this doesn't work)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can make this work in a data step but not in a macro and I don't know what I'm doing wrong.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let Filedate = 201906;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;format y ddmmyy10.;&lt;BR /&gt;y = intnx("month",input(cats(&amp;amp;Filedate.,"01"),yymmdd8.),0,"E");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 13:19:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578389#M164031</guid>
      <dc:creator>Stats10</dc:creator>
      <dc:date>2019-08-01T13:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578401#M164036</link>
      <description>&lt;P&gt;What do you mean by&amp;nbsp;&lt;STRONG&gt;&lt;SPAN&gt;this doesn't work&lt;/SPAN&gt;&lt;/STRONG&gt; ?&lt;/P&gt;
&lt;P&gt;What error or warning do you have in the log?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 13:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578401#M164036</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-08-01T13:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578405#M164038</link>
      <description>&lt;P&gt;Hi Smuel,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error message I get when I run this line of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let MonthEnd = %sysfunc(intnx(month,input(cats(&amp;amp;filedate.,01),yymmdd8.),0,E),date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Required operator not found in expression: input(cats(201906,01),yymmdd8.)&lt;BR /&gt;ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC&lt;BR /&gt;or %QSYSFUNC function reference is terminated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand what it means and I've tried many different variations.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 13:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578405#M164038</guid>
      <dc:creator>Stats10</dc:creator>
      <dc:date>2019-08-01T13:52:03Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578414#M164041</link>
      <description>&lt;P&gt;I think you need repeat&amp;nbsp;&lt;STRONG&gt;%sysfunc&lt;/STRONG&gt; for every sas function, something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let MonthEnd = %sysfunc(intnx(month,%sysfunc(input(%sysfunc(cats(&amp;amp;filedate.,01)),yymmdd8.)),0,E),date9.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578414#M164041</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-08-01T14:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578415#M164042</link>
      <description>&lt;P&gt;Macro language does not support the INPUT function.&amp;nbsp; If you apply %SYSFUNC, you could use either INPUTN or INPUTC:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let MonthEnd = %sysfunc(intnx(month, %sysfunc(inputn(&amp;amp;filedate.01,yymmdd8.)) ,0,E),date9.); &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's untested at this point, so give it a shot and see if it works for you.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578415#M164042</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-01T14:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578417#M164044</link>
      <description>Hi Shmuel, this gives me the same error message.</description>
      <pubDate>Thu, 01 Aug 2019 14:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578417#M164044</guid>
      <dc:creator>Stats10</dc:creator>
      <dc:date>2019-08-01T14:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578418#M164045</link>
      <description>&lt;P&gt;Hi Astounding,&lt;BR /&gt;&lt;BR /&gt;it worked! Thank you so much! So I had to use the %sysfunc again (like Shmuel said) but remove the "cats". I wouldn't have guessed in a million years. I did try the inputn but always kept the "cats" in.Thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578418#M164045</guid>
      <dc:creator>Stats10</dc:creator>
      <dc:date>2019-08-01T14:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578421#M164047</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Every function you want to call in macro code needs its own %SYSFUNC() call.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;There is no need for CATS() in macro code. Just expand the values next to each other and they are concatenated.
&lt;UL&gt;
&lt;LI&gt;You don't need to add the day of the month anyway. Just use the YYMMN informat.&lt;/LI&gt;
&lt;/UL&gt;
&lt;/LI&gt;
&lt;LI&gt;You cannot use INPUT(), but must use INPUTN() , or INPUTC() if you want to generate a character value instead of a numeric value.&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let filedate = 201906;
%let monthend= %sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;filedate,yymmn6)),0,E),date9);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;376   %put &amp;amp;=monthend;
MONTHEND=30JUN2019&lt;/PRE&gt;
&lt;P&gt;Do you really want the macro variable to have a string that looks like a date value in DATE9 format?&amp;nbsp; Or do you want it to have an actual date value?&amp;nbsp; Or perhaps a date literal?&amp;nbsp; How are you planning to use it?&lt;/P&gt;
&lt;PRE&gt;381   %let monthend= %sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;filedate,yymmn6)),0,E),date9);
382   %put &amp;amp;=monthend;
MONTHEND=30JUN2019
383   %let monthend= %sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;filedate,yymmn6)),0,E));
384   %put &amp;amp;=monthend;
MONTHEND=21730
385   %let monthend= "%sysfunc(intnx(month,%sysfunc(inputn(&amp;amp;filedate,yymmn6)),0,E),date9)"d;
386   %put &amp;amp;=monthend;
MONTHEND="30JUN2019"d&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578421#M164047</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-01T14:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578423#M164049</link>
      <description>Hi Tom,&lt;BR /&gt;&lt;BR /&gt;I did try the Inputn function but it didn't work either, so I gave up. Yes, I do need the macro to look like a string initially because it's being used elsewhere as well in that format. So I wanted to kill two birds with one stone essentially. This is exactly what I needed. Thanks for your response as well.</description>
      <pubDate>Thu, 01 Aug 2019 14:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578423#M164049</guid>
      <dc:creator>Stats10</dc:creator>
      <dc:date>2019-08-01T14:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578427#M164052</link>
      <description>Thanks for the extra versions Tom! Cool that I don't need to concatenate this way! Will use that then. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578427#M164052</guid>
      <dc:creator>Stats10</dc:creator>
      <dc:date>2019-08-01T14:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Convert text to date in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578428#M164053</link>
      <description>Mostly like the problem you had with using INPUTN as you were still not converting all of your other function calls.  So the YYMMDD informat will not be able to convert a string like CATS(.... into a valid date.&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-text-to-date-in-macro/m-p/578428#M164053</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-01T14:28:43Z</dc:date>
    </item>
  </channel>
</rss>

