<?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: Macro Variable Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947698#M370945</link>
    <description>&lt;P&gt;Look carefully at the SAS code you asked the macro processor to generate for you.&lt;/P&gt;
&lt;P&gt;If the macro variable LASTDAY has the string 09/30/2024 and you use it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;testdate = &amp;amp;lastday;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you asked SAS to run this line of code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;testdate = 09/30/2024;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since 9 divided by 30 divided by 2024 is going to be between 0 and 1 the MMDDYY10. format will display that as 01/01/1960 since the number 0 is used by SAS to represent the first day of 1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why did you format the value at all?&amp;nbsp; If you just use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lastday=%sysfunc(intnx(month,%sysfunc(today()),-1,e));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you should get LASTDAY set to the string&amp;nbsp;23649 which the MMDDYY10. format will display as 09/30/2024.&lt;/P&gt;
&lt;PRE&gt;338  %let lastday=%sysfunc(intnx(month,%sysfunc(today()),-1,e));
339
340  data test;
341    x=&amp;amp;lastday;
342    put x= x mmddyy10.;
343  run;

x=23649 09/30/2024
&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Oct 2024 16:02:32 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-10-16T16:02:32Z</dc:date>
    <item>
      <title>Macro Variable Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947693#M370941</link>
      <description>&lt;P&gt;I am apparently not seeing something simple in this code.&amp;nbsp; The below code returns a testdate of 1/1/60, but the log somehow is recognizing the macro variable correctly as 9/30/24.&amp;nbsp; How do i get that macro variable date into my dataset?&amp;nbsp; I think i've done this a million times but today it doesn't seem to be working for me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let lastday = %sysfunc(intnx(month,%sysfunc(today()),-1,e),mmddyy10.);&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt;set have;&lt;BR /&gt;testdate = &amp;amp;lastday;&lt;BR /&gt;format testdate mmddyy10.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;log:&lt;/P&gt;
&lt;P&gt;28 %let lastday = %sysfunc(intnx(month,%sysfunc(today()),-1,e),mmddyy10.);&lt;BR /&gt;29 &lt;BR /&gt;30 data test;&lt;BR /&gt;31 set have;&lt;BR /&gt;32 testdate = &amp;amp;lastday;&lt;BR /&gt;SYMBOLGEN: Macro variable LASTDAY resolves to 09/30/2024&lt;BR /&gt;33 format testdate mmddyy10.;&lt;BR /&gt;34 run;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 15:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947693#M370941</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2024-10-16T15:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947698#M370945</link>
      <description>&lt;P&gt;Look carefully at the SAS code you asked the macro processor to generate for you.&lt;/P&gt;
&lt;P&gt;If the macro variable LASTDAY has the string 09/30/2024 and you use it like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;testdate = &amp;amp;lastday;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you asked SAS to run this line of code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;testdate = 09/30/2024;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since 9 divided by 30 divided by 2024 is going to be between 0 and 1 the MMDDYY10. format will display that as 01/01/1960 since the number 0 is used by SAS to represent the first day of 1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why did you format the value at all?&amp;nbsp; If you just use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lastday=%sysfunc(intnx(month,%sysfunc(today()),-1,e));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you should get LASTDAY set to the string&amp;nbsp;23649 which the MMDDYY10. format will display as 09/30/2024.&lt;/P&gt;
&lt;PRE&gt;338  %let lastday=%sysfunc(intnx(month,%sysfunc(today()),-1,e));
339
340  data test;
341    x=&amp;amp;lastday;
342    put x= x mmddyy10.;
343  run;

x=23649 09/30/2024
&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Oct 2024 16:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947698#M370945</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-16T16:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947700#M370946</link>
      <description>Perfect - Thanks.</description>
      <pubDate>Wed, 16 Oct 2024 16:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947700#M370946</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2024-10-16T16:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Variable Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947703#M370948</link>
      <description>&lt;P&gt;Do the arithmetic.&amp;nbsp; 9 divided by 30 is 0.3. Divide that by 2024. The result is 0.0001482213 approximately.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Date Formats use number of days from 1 Jan 1960. So any value between 0 and is 1 Jan 1960, 1 is 2 Jan, 2 is 3 jan and so on.&lt;/P&gt;
&lt;P&gt;The code you created resolves the macro variable exactly as text:&lt;/P&gt;
&lt;PRE&gt;data test;
testdate = 09/30/2024;
format testdate mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;You told it to divide some values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only way to write a LITERAL DATE is to use something that looks like the Date9 or similar formats and to be treated as date must be in quotes and followed by a &lt;span class="lia-unicode-emoji" title=":anguished_face:"&gt;😧&lt;/span&gt;&amp;nbsp; '30SEP2024'D;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However if you did not format the date created by the macro:&lt;/P&gt;
&lt;PRE&gt;%let lastday = %sysfunc(intnx(month,%sysfunc(today()),-1,e));
data test;
testdate = &amp;amp;lastday.;
format testdate mmddyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;Then Lastday will have the correct numeric value of number of days and the format then makes sense to display that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are so many ways to display dates, times and datetime values, just check on the SAS supplied formats, that they picked one for coding literal values. The '09SEP2024'd version has the property of being relatively legible across cultures where dd/mm or mm/dd can be confused quite easily for about a third of a year. Similar if you use time literal values: "15:20:16"T note the default 24 hour clodk, or datetime values "09SEP2024:15:20:16"dt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 16:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Variable-Date/m-p/947703#M370948</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-10-16T16:15:30Z</dc:date>
    </item>
  </channel>
</rss>

