<?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: How do I get a macro that prints yesterday's date in SAS Date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960359#M374566</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/417025"&gt;@InêsMaximiano&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to use it for some filters. We need to do datepart(dateX) &amp;gt; yesterdaydate and&amp;nbsp;datepart(dateX) &amp;lt;= dateY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I do datepart(dateX) and get a SAS Date, so that's why I need all other dates to be also in the format of SAS Date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the DateY I'm doing the following:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select DateY format ddyyyy10.&lt;BR /&gt;into :DateY&lt;BR /&gt;from DE.TRACK&lt;BR /&gt;where TABLE = "TRACK";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a more correct way to do it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS will allow you to create some pretty complicated date /datetime formats. But the meaning has to be clear. For example you have DDYYYY10. How would 31DEC2024 appear with that format? There are functions and formats related to JULIAN dates, which use the day of the year (3 digits to accomaded 365/366) plus the year (2 or 4 digits). But asking for what appears to be 2 digits for Day and 4 for year and then using 10 characters to display sounds likely to have other issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2025 02:35:59 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2025-02-27T02:35:59Z</dc:date>
    <item>
      <title>How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960267#M374545</link>
      <description>&lt;P&gt;Hi! Can you please help me create a macro that always&amp;nbsp;prints yesterday's date in SAS Date please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;call symput('yesterday', put(intnx('day', today(), -1), ddyyyy10.));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;yesterday;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I get the following error:&amp;nbsp;Format DDYYYY was not found or could not be loaded.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 15:42:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960267#M374545</guid>
      <dc:creator>InêsMaximiano</dc:creator>
      <dc:date>2025-02-26T15:42:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960269#M374546</link>
      <description>&lt;P&gt;There is no such format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any valid format should work. Alphabetic list of valid DATE or DATETIME or TIME formats:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/allprodslang/syntaxByCategory-format.htm#p0aa41u6lidfz1n1n977se5xgl2s" target="_blank" rel="noopener"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/allprodslang/syntaxByCategory-format.htm#p0aa41u6lidfz1n1n977se5xgl2s&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Be sure to choose a DATE format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you are going to perform arithmetic or logical operations with this macro variable, you would be better off not formatting it. See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 15:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960269#M374546</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T15:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960270#M374547</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('yesterday', put(intnx('day', today(), -1), ddmmyy10.));
run;

%put &amp;amp;=yesterday;

data _null_;
call symputx('yesterday', put(intnx('day', today(), -1), worddate.));
run;

%put &amp;amp;=yesterday;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 15:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960270#M374547</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2025-02-26T15:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960271#M374548</link>
      <description>Should I do it only this:&lt;BR /&gt;data _null_;&lt;BR /&gt;    call symput('dados_atuais', intnx('day', today(), -1));&lt;BR /&gt;run;</description>
      <pubDate>Wed, 26 Feb 2025 15:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960271#M374548</guid>
      <dc:creator>InêsMaximiano</dc:creator>
      <dc:date>2025-02-26T15:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960272#M374549</link>
      <description>&lt;P&gt;That would work if you are planning to use the data for arithmetic or logical operations. If you want it to appear in human readable form like for titles or labels, then you need it formatted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use CALL SYMPUTX&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 15:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960272#M374549</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T15:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960274#M374550</link>
      <description>&lt;P&gt;I need to use it for some filters. We need to do datepart(dateX) &amp;gt; yesterdaydate and&amp;nbsp;datepart(dateX) &amp;lt;= dateY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I do datepart(dateX) and get a SAS Date, so that's why I need all other dates to be also in the format of SAS Date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the DateY I'm doing the following:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select DateY format ddyyyy10.&lt;BR /&gt;into :DateY&lt;BR /&gt;from DE.TRACK&lt;BR /&gt;where TABLE = "TRACK";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a more correct way to do it?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 16:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960274#M374550</guid>
      <dc:creator>InêsMaximiano</dc:creator>
      <dc:date>2025-02-26T16:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960275#M374551</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/417025"&gt;@InêsMaximiano&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to use it for some filters. We need to do datepart(dateX) &amp;gt; yesterdaydate and&amp;nbsp;datepart(dateX) &amp;lt;= dateY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I do datepart(dateX) and get a SAS Date, so that's why I need all other dates to be also in the format of SAS Date.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Incorrect. SAS does all comparisons on unformatted values. Even if the date looks to you as 01JAN2025 (this is a formatted date), SAS still uses the unformatted date when it does arithmetic or comparisons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fakedata;
    date='01JAN2025'd;
    output;
    date='26FEB2026'd;
    output;
    format date date9.;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code correctly finds the dates before yesterday&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; /* UNFORMATTED DATE IN MACRO VARIABLE */
    call symputx('yesterday',intnx('day',today(),-1));
run;

data want;
    set fakedata;
    if date&amp;lt;&amp;amp;yesterday;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code with a formatted date produces errors&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; /* FORMATTED DATE IN MACRO VARIABLE */
    call symputx('yesterday',put(intnx('day',today(),-1),date9.));
run;

data want;
    set fakedata;
    if date&amp;lt;&amp;amp;yesterday;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 16:18:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960275#M374551</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T16:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960277#M374552</link>
      <description>But it was giving me errors when comparing datepart(dateX) with yesterdaydate which was YYMMDD10. and dateY which was ddmmyy8.</description>
      <pubDate>Wed, 26 Feb 2025 16:12:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960277#M374552</guid>
      <dc:creator>InêsMaximiano</dc:creator>
      <dc:date>2025-02-26T16:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960278#M374553</link>
      <description>&lt;P&gt;Use unformatted date values in your macro variables, as I show in the examples above.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 16:18:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960278#M374553</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T16:18:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960283#M374554</link>
      <description>I saw the examples now! Thank you so much!&lt;BR /&gt;&lt;BR /&gt;One last question, how can I get DateY&lt;BR /&gt;from the table DE.TRACK, but removing the format?</description>
      <pubDate>Wed, 26 Feb 2025 16:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960283#M374554</guid>
      <dc:creator>InêsMaximiano</dc:creator>
      <dc:date>2025-02-26T16:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960284#M374555</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/417025"&gt;@InêsMaximiano&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to use it for some filters. We need to do&lt;/P&gt;
&lt;P&gt;datepart(dateX) &amp;gt; yesterdaydate and&amp;nbsp;datepart(dateX) &amp;lt;= dateY&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I assume you want to replace the&amp;nbsp;yesterdaydate in that formula?&lt;/P&gt;
&lt;P&gt;So you can put there anything that evaluates to a valid date.&lt;/P&gt;
&lt;P&gt;So either a formula, like TODAY()-1, or a date literal, like&amp;nbsp;'25FEB2025'd, or just the actual number of days since 1960 that such a date literal represents, like&amp;nbsp;23797.&amp;nbsp; Or even compare the datatime value to a datetime literal instead.&lt;/P&gt;
&lt;P&gt;Some examples:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datepart(dateX) &amp;gt; (today()-1) and&amp;nbsp;datepart(dateX) &amp;lt;= dateY
datepart(dateX) &amp;gt; (intnx('day',today(),-1)) and&amp;nbsp;datepart(dateX) &amp;lt;= dateY
datepart(dateX) &amp;gt; '25FEB2025'd and&amp;nbsp;datepart(dateX) &amp;lt;= dateY
datepart(dateX) &amp;gt; "25FEB2025"d and&amp;nbsp;datepart(dateX) &amp;lt;= dateY
datepart(dateX) &amp;gt; 23797  and&amp;nbsp;datepart(dateX) &amp;lt;= dateY
dateX &amp;gt;= "26FEB2025:00:00"dt and&amp;nbsp;datepart(dateX) &amp;lt;= dateY&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;PS Unless there is a need to include leading and/or trailing spaces in the macro variable you should be using the normal CALL SYMPUTX() method and not the ancient CALL SYMPUT() method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 16:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960284#M374555</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-26T16:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960286#M374556</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/417025"&gt;@InêsMaximiano&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I saw the examples now! Thank you so much!&lt;BR /&gt;&lt;BR /&gt;One last question, how can I get DateY&lt;BR /&gt;from the table DE.TRACK, but removing the format?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You don't have to change the variables in a SAS data set. You can leave them alone. It works fine if they are formatted. It works fine if they are unformatted. Why? Because SAS always works with unformatted values for arithmetic and logical operations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro variables are different, they will usually not work formatted for arithmetic and logical operations (without additional effort).&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2025 16:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960286#M374556</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-02-26T16:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a macro that prints yesterday's date in SAS Date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960359#M374566</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/417025"&gt;@InêsMaximiano&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to use it for some filters. We need to do datepart(dateX) &amp;gt; yesterdaydate and&amp;nbsp;datepart(dateX) &amp;lt;= dateY&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I do datepart(dateX) and get a SAS Date, so that's why I need all other dates to be also in the format of SAS Date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the DateY I'm doing the following:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select DateY format ddyyyy10.&lt;BR /&gt;into :DateY&lt;BR /&gt;from DE.TRACK&lt;BR /&gt;where TABLE = "TRACK";&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a more correct way to do it?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS will allow you to create some pretty complicated date /datetime formats. But the meaning has to be clear. For example you have DDYYYY10. How would 31DEC2024 appear with that format? There are functions and formats related to JULIAN dates, which use the day of the year (3 digits to accomaded 365/366) plus the year (2 or 4 digits). But asking for what appears to be 2 digits for Day and 4 for year and then using 10 characters to display sounds likely to have other issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2025 02:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-get-a-macro-that-prints-yesterday-s-date-in-SAS-Date/m-p/960359#M374566</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-02-27T02:35:59Z</dc:date>
    </item>
  </channel>
</rss>

