<?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 How to extract datepart from macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816577#M322338</link>
    <description>&lt;P&gt;How to extract datepart from macro variable&lt;/P&gt;&lt;P&gt;%let dt1='25APR2022:00:00:00.0000';&lt;/P&gt;&lt;P&gt;DATA WANT;&lt;/P&gt;&lt;P&gt;FORMAT DT1 MMDDYY10.;&lt;/P&gt;&lt;P&gt;START_DT=DATEPART("&amp;amp;DT1."d);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Issue:&lt;/P&gt;&lt;P&gt;Output should be 04/25/2022, but displays as 01/01/1960.&lt;/P&gt;&lt;P&gt;Pls help&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jun 2022 00:19:06 GMT</pubDate>
    <dc:creator>West26</dc:creator>
    <dc:date>2022-06-06T00:19:06Z</dc:date>
    <item>
      <title>How to extract datepart from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816577#M322338</link>
      <description>&lt;P&gt;How to extract datepart from macro variable&lt;/P&gt;&lt;P&gt;%let dt1='25APR2022:00:00:00.0000';&lt;/P&gt;&lt;P&gt;DATA WANT;&lt;/P&gt;&lt;P&gt;FORMAT DT1 MMDDYY10.;&lt;/P&gt;&lt;P&gt;START_DT=DATEPART("&amp;amp;DT1."d);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Issue:&lt;/P&gt;&lt;P&gt;Output should be 04/25/2022, but displays as 01/01/1960.&lt;/P&gt;&lt;P&gt;Pls help&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 00:19:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816577#M322338</guid>
      <dc:creator>West26</dc:creator>
      <dc:date>2022-06-06T00:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract datepart from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816580#M322339</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I think the basic issue is that you're telling SAS the value is a date constant with the "&amp;amp;macvar"d but you should be telling SAS That it is a datetime constant using the "&amp;amp;macvar"dt specification. Do you want a DATA step variable or do you just want another macro variable? You could just do the DATEPART inside of a %SYSFUNC if you just needed a macro variable:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1654476929927.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72001i40C82BDA27AF838B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1654476929927.png" alt="Cynthia_sas_0-1654476929927.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note how the values can be created as macro variables using %LET or can also be used in a DATA step program. Either way, to use DATEPART with a datetime value, you need to use the dt, not just the d for the constant.&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 00:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816580#M322339</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2022-06-06T00:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract datepart from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816581#M322340</link>
      <description>&lt;P&gt;Thank you so much for your time and effort. Really appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 01:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816581#M322340</guid>
      <dc:creator>West26</dc:creator>
      <dc:date>2022-06-06T01:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract datepart from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816583#M322342</link>
      <description>&lt;P&gt;Your code illustrates two interesting points about the flexibility of specifying a DATE constant.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You can have extra quotes in the value.&lt;/LI&gt;
&lt;LI&gt;You can include a time part string that will be ignored when calculating a DATE&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;But your actual problem is that you used the DATEPART() function on a value that was already a DATE value.&amp;nbsp; Since the DATEPART() function is essentially just dividing the number of second by 86000 seconds per day to get a number of days the result of that when applied to any reasonable date value is going to end as zero, the base date value that SAS uses to number days, which is 01JAN1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So either convert the string directly into a DATE literal.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;START_DT="&amp;amp;DT1."d;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or convert it into a DATETIME literal, and then you can later convert the number of seconds into number of days.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;START_DT=DATEPART("&amp;amp;DT1."dt);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 02:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816583#M322342</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-06T02:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract datepart from macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816584#M322343</link>
      <description>Thank you for explaining in such a great detail. It is really helpful.</description>
      <pubDate>Mon, 06 Jun 2022 02:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-datepart-from-macro-variable/m-p/816584#M322343</guid>
      <dc:creator>West26</dc:creator>
      <dc:date>2022-06-06T02:34:11Z</dc:date>
    </item>
  </channel>
</rss>

