<?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: Converting a SAS Date into a DatePart in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-SAS-Date-into-a-DatePart/m-p/691703#M210569</link>
    <description>&lt;P&gt;You've done it correctly but have not formatted it. Computer applications often store dates as the number of days from a reference point so 22092 is the number of days from January 1, 1960. To have it show as a date you apply a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI I strongly recommend against coding so that your input data set has the same name as the output data set (DATA/SET statements). This makes it hard to debug your code and is not a good practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data SASCDC_2.Arias_Median_Days_Monitoring2;
   Set SASCDC_2.Arias_Median_Days_Monitoring;

   C_Date=DatePart(Created_On);
   format c_date ddmmyyd10.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65907"&gt;@wlierman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is a pretty basic question that nonetheless keeps tripping me up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datetimevariable.&amp;nbsp; I extract the datepart and it is returned as a SAS date form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want a a DatePart form&amp;nbsp; like&amp;nbsp; dd/mm/yy. Here is the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data SASCDC_2.Arias_Median_Days_Monitoring;
   Set SASCDC_2.Arias_Median_Days_Monitoring;
   C_Date=DatePart(Created_On);
   Create = ??? (C_Date);
   rename Create = Create_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put the ? marks in there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have the following output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Created_on&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C_date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26JUN20:09:40:24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22092&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I want Create (in code) to contain the DatePart representation of C_date&lt;/P&gt;
&lt;P&gt;like&amp;nbsp; 26JUN20&amp;nbsp; and so on for the rest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wlierman&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Oct 2020 23:16:09 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-10-14T23:16:09Z</dc:date>
    <item>
      <title>Converting a SAS Date into a DatePart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-SAS-Date-into-a-DatePart/m-p/691700#M210567</link>
      <description>&lt;P&gt;This is a pretty basic question that nonetheless keeps tripping me up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datetimevariable.&amp;nbsp; I extract the datepart and it is returned as a SAS date form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want a a DatePart form&amp;nbsp; like&amp;nbsp; dd/mm/yy. Here is the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data SASCDC_2.Arias_Median_Days_Monitoring;
   Set SASCDC_2.Arias_Median_Days_Monitoring;
   C_Date=DatePart(Created_On);
   Create = ??? (C_Date);
   rename Create = Create_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put the ? marks in there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have the following output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Created_on&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C_date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26JUN20:09:40:24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22092&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I want Create (in code) to contain the DatePart representation of C_date&lt;/P&gt;
&lt;P&gt;like&amp;nbsp; 26JUN20&amp;nbsp; and so on for the rest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wlierman&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 23:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-SAS-Date-into-a-DatePart/m-p/691700#M210567</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2020-10-14T23:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SAS Date into a DatePart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-SAS-Date-into-a-DatePart/m-p/691703#M210569</link>
      <description>&lt;P&gt;You've done it correctly but have not formatted it. Computer applications often store dates as the number of days from a reference point so 22092 is the number of days from January 1, 1960. To have it show as a date you apply a format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI I strongly recommend against coding so that your input data set has the same name as the output data set (DATA/SET statements). This makes it hard to debug your code and is not a good practice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data SASCDC_2.Arias_Median_Days_Monitoring2;
   Set SASCDC_2.Arias_Median_Days_Monitoring;

   C_Date=DatePart(Created_On);
   format c_date ddmmyyd10.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a great, but longer and in depth, reference for dates and times in SAS&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65907"&gt;@wlierman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is a pretty basic question that nonetheless keeps tripping me up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a datetimevariable.&amp;nbsp; I extract the datepart and it is returned as a SAS date form.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want a a DatePart form&amp;nbsp; like&amp;nbsp; dd/mm/yy. Here is the code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data SASCDC_2.Arias_Median_Days_Monitoring;
   Set SASCDC_2.Arias_Median_Days_Monitoring;
   C_Date=DatePart(Created_On);
   Create = ??? (C_Date);
   rename Create = Create_date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I put the ? marks in there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I have the following output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Created_on&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C_date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26JUN20:09:40:24&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 22092&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I want Create (in code) to contain the DatePart representation of C_date&lt;/P&gt;
&lt;P&gt;like&amp;nbsp; 26JUN20&amp;nbsp; and so on for the rest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wlierman&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2020 23:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-SAS-Date-into-a-DatePart/m-p/691703#M210569</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-14T23:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Converting a SAS Date into a DatePart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-a-SAS-Date-into-a-DatePart/m-p/691741#M210593</link>
      <description>&lt;P&gt;Thank you for your review and solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also thank you for the coding tips as well as well as the link to Andrew Karp's article.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;wlierman&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 03:56:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-a-SAS-Date-into-a-DatePart/m-p/691741#M210593</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2020-10-15T03:56:18Z</dc:date>
    </item>
  </channel>
</rss>

