<?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: date extract in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898993#M355337</link>
    <description>&lt;P&gt;If this is a numeric value in a numeric variable, what you are showing (without the quotes) is a date/time value, and so the DATEPART function extracts the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is character ... well ... it shouldn't be. Date values and date/time values should always be numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does PROC CONTENTS show for this variable?&lt;/P&gt;</description>
    <pubDate>Tue, 17 Oct 2023 18:13:13 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-10-17T18:13:13Z</dc:date>
    <item>
      <title>date extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898992#M355336</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;how to extract date from this type of date &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;' &lt;/SPAN&gt;&lt;SPAN&gt;2018-08-26 17:51:30.8770000 +00:00'?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 18:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898992#M355336</guid>
      <dc:creator>Eugenio211</dc:creator>
      <dc:date>2023-10-17T18:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: date extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898993#M355337</link>
      <description>&lt;P&gt;If this is a numeric value in a numeric variable, what you are showing (without the quotes) is a date/time value, and so the DATEPART function extracts the date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is character ... well ... it shouldn't be. Date values and date/time values should always be numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What does PROC CONTENTS show for this variable?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 18:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898993#M355337</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-17T18:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: date extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898994#M355338</link>
      <description>this is what I get when using datepart:&lt;BR /&gt;ERROR: Function DATEPART requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Character expression requires a character format.&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Oct 2023 18:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898994#M355338</guid>
      <dc:creator>Eugenio211</dc:creator>
      <dc:date>2023-10-17T18:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: date extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898995#M355339</link>
      <description>this is my step:&lt;BR /&gt;proc sql;&lt;BR /&gt;create table PaidAhead as&lt;BR /&gt;select l.CUSTOMER_KEY,l.LOAN_KEY,l.DATE_ENTERED&lt;BR /&gt;		,datepart(PAYOFF_DATE) as PAID_OFF_DATE format date9.&lt;BR /&gt;		,l.product_type&lt;BR /&gt;from DataSet1 L&lt;BR /&gt;join DataSet2 d on l.LOAN_KEY = d.LOAN_KEY&lt;BR /&gt;;quit;</description>
      <pubDate>Tue, 17 Oct 2023 18:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898995#M355339</guid>
      <dc:creator>Eugenio211</dc:creator>
      <dc:date>2023-10-17T18:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: date extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898996#M355340</link>
      <description>&lt;P&gt;Obvi you have a character variable that looks like a date/time; but it clearly is not a date/time since date/time values cannot be character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have to convert this to numeric, with INPUT function and the proper informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    datetime=' 2018-08-26 17:51:30.8770000 +00:00';
    datetime_numeric=input(datetime, anydtdtm.);
    date=datepart(datetime_numeric);
    format date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do yourself a favor and do not use character strings for dates, times and datetimes. These variables should be NUMERIC, always, 100% of the time, no exceptions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 18:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/898996#M355340</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-17T18:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: date extract</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/899014#M355351</link>
      <description>&lt;P&gt;Perhaps a little simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   date = input(big_long_datetime_string, : yymmdd10.);
   drop big_long_datetime_string;
   formate date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gets you the DATE as a proper, numeric SAS date, while getting rid of the time part.&amp;nbsp; If memory serves, however, you will need to use a DATA step because SQL will not allow the INPUT function.&amp;nbsp; (Unless times have changed, but I doubt it.)&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2023 19:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-extract/m-p/899014#M355351</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-17T19:43:18Z</dc:date>
    </item>
  </channel>
</rss>

