<?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 Date variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Date-variable/m-p/923977#M41440</link>
    <description>&lt;P&gt;I have the following date variable:&lt;/P&gt;&lt;P&gt;Collection_date&lt;/P&gt;&lt;P&gt;1/1/2023 5:27:00 PM&lt;/P&gt;&lt;P&gt;2/2/2023 2:40:00 PM&lt;/P&gt;&lt;P&gt;3/4/2023 12:02:00 PM&lt;/P&gt;&lt;P&gt;4/6/2023 11:59:00 AM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I would like to convert it or create a new date variable and have it in the following format:&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;01Jan2023&lt;/P&gt;&lt;P&gt;02Feb2023&lt;BR /&gt;04Mar2023&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly help with&amp;nbsp;the appropriate code for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Apr 2024 14:28:45 GMT</pubDate>
    <dc:creator>shami</dc:creator>
    <dc:date>2024-04-11T14:28:45Z</dc:date>
    <item>
      <title>Date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Date-variable/m-p/923977#M41440</link>
      <description>&lt;P&gt;I have the following date variable:&lt;/P&gt;&lt;P&gt;Collection_date&lt;/P&gt;&lt;P&gt;1/1/2023 5:27:00 PM&lt;/P&gt;&lt;P&gt;2/2/2023 2:40:00 PM&lt;/P&gt;&lt;P&gt;3/4/2023 12:02:00 PM&lt;/P&gt;&lt;P&gt;4/6/2023 11:59:00 AM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I would like to convert it or create a new date variable and have it in the following format:&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;01Jan2023&lt;/P&gt;&lt;P&gt;02Feb2023&lt;BR /&gt;04Mar2023&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly help with&amp;nbsp;the appropriate code for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 14:28:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Date-variable/m-p/923977#M41440</guid>
      <dc:creator>shami</dc:creator>
      <dc:date>2024-04-11T14:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Date-variable/m-p/923979#M41441</link>
      <description>&lt;P&gt;Run PROC CONTENTS on your existing dataset. Is the current variable NUMERIC or CHARACTER?&amp;nbsp; Does it have a FORMAT attached to it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is NUMERIC then you have a DATETIME value.&amp;nbsp; You could just change the format attached to the variable to have it print in that style.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format old dtdate9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can use the DATEPART() function to convert it to a DATE value.&amp;nbsp; Then you could attach the DATE9. format to it so it will print in the style you show.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new=datepart(old);
format new date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since both DATETIME and DATE values are stored as NUMERIC variables you could replace the values of the original variable instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;old=datepart(old);
format old date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it is CHARACTER then you can use the INPUT() function with the MMDDYY informat to convert it to a DATE value.&amp;nbsp; Note that your strings seem to using inconsistent length for the date part.&amp;nbsp; So you will want to use SCAN() to pull out just the first word from the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new=input(scan(old,1,' '),mmddyy10.);
format new date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Since DATE values are numeric you will need to make a NEW variable.&amp;nbsp; If you wanted to store it back into the old variable you would need to add a PUT() function call to generate a character string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;old=put(input(scan(old,1,' '),mmddyy10.),date9.);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2024 14:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Date-variable/m-p/923979#M41441</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-11T14:46:47Z</dc:date>
    </item>
  </channel>
</rss>

