<?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 SAS date format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825959#M326240</link>
    <description>&lt;P&gt;I have extracted the date from a file and it is in the format of&amp;nbsp;09-30-21 and I have to convert this to the format&amp;nbsp;30Sep2021. Is there a way I could do this?&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2022 15:25:44 GMT</pubDate>
    <dc:creator>eroolpal</dc:creator>
    <dc:date>2022-07-28T15:25:44Z</dc:date>
    <item>
      <title>SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825959#M326240</link>
      <description>&lt;P&gt;I have extracted the date from a file and it is in the format of&amp;nbsp;09-30-21 and I have to convert this to the format&amp;nbsp;30Sep2021. Is there a way I could do this?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825959#M326240</guid>
      <dc:creator>eroolpal</dc:creator>
      <dc:date>2022-07-28T15:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825961#M326241</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/383316"&gt;@eroolpal&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;you could try the format statement (&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/n0d5oq7e0oia0wn13nsins0x8nmh.htm#:~:text=DEFAULT%3Ddefault%2Dformat,-specifies%20a%20temporary&amp;amp;text=If%20you%20omit%20DEFAULT%3D%2C%20SAS,as%20the%20default%20character%20format.&amp;amp;text=Use%20this%20option%20only%20in%20a%20DATA%20step." target="_blank"&gt;SAS Help Center: FORMAT Statement&lt;/A&gt;) in a data step with the format "date9.".&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;Markus&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825961#M326241</guid>
      <dc:creator>MarkusWeick</dc:creator>
      <dc:date>2022-07-28T15:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825963#M326242</link>
      <description>If 09-30-21 is not a sting but a SAS date in DDMMYYD. format, &lt;BR /&gt;you can just apply date9. format to get 30Sep2021:&lt;BR /&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p1wj0wt2ebe2a0n1lv4lem9hdc0v.htm&lt;/A&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825963#M326242</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-07-28T15:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825969#M326245</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/383316"&gt;@eroolpal&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have extracted the date from a file and it is in the format of&amp;nbsp;09-30-21 and I have to convert this to the format&amp;nbsp;30Sep2021. Is there a way I could do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you mean by "extracted"?&amp;nbsp; What do you mean by "file"?&lt;/P&gt;
&lt;P&gt;If you using a data step to read a text file then using the MMDDYY informat to read text like 09-30-21 into dates.&amp;nbsp; If your date strings really only have two digits for the year you could have trouble.&amp;nbsp;&lt;A href="https://en.wikipedia.org/wiki/Year_2000_problem" target="_blank"&gt;https://en.wikipedia.org/wiki/Year_2000_problem&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have a variable with date values (number of days since 1960) then you can use any of the various SAS formats that display date values. Looks like you want the DATE9 format which would display that date as 30SEP2021.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825969#M326245</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-28T15:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825971#M326247</link>
      <description>Thanks. Its in the string format. how do I convert that to a date format first.</description>
      <pubDate>Thu, 28 Jul 2022 15:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825971#M326247</guid>
      <dc:creator>eroolpal</dc:creator>
      <dc:date>2022-07-28T15:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825972#M326248</link>
      <description>yes I do have a file. I am extracting it as a string and then will want to change this to a date format and then need to change it to 30Sep2021</description>
      <pubDate>Thu, 28 Jul 2022 15:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825972#M326248</guid>
      <dc:creator>eroolpal</dc:creator>
      <dc:date>2022-07-28T15:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825980#M326251</link>
      <description>data want;&lt;BR /&gt;informat A DDMMYYD. ;&lt;BR /&gt;input A;&lt;BR /&gt;format A date9.;&lt;BR /&gt;cards;&lt;BR /&gt;09-30-21&lt;BR /&gt;run;&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi24/Coders/p073-24.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi24/Coders/p073-24.pdf&lt;/A&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:58:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825980#M326251</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-07-28T15:58:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825984#M326253</link>
      <description>&lt;P&gt;Thanks. this code worked for me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.ds;&lt;BR /&gt;date_string = "09-30-21";&lt;BR /&gt;date_number = input(date_string, MMDDYY8.);&lt;BR /&gt;format date_number date9.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 16:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825984#M326253</guid>
      <dc:creator>eroolpal</dc:creator>
      <dc:date>2022-07-28T16:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825987#M326254</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/383316"&gt;@eroolpal&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;yes I do have a file. I am extracting it as a string and then will want to change this to a date format and then need to change it to 30Sep2021&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you already have a character variable, let's call it STRING, then use the INPUT() function with an appropriate informat specification to convert that string into a number that SAS can treat as a date.&amp;nbsp; Then attach a date type format to it so it prints in a style that humans will recognize as a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if your existing dataset is named HAVE here is how you could make a new dataset and a new variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  date = input(string,mmddyy11.);
  format date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that you cannot change the type of an existing variable.&amp;nbsp; So it you want the new variable to use the name that is already being used by the character variable then add a RENAME (and possibly and DROP) statement.&amp;nbsp; So if the existing variable named DATE and you want to use DATE as the name of the new numeric variable you might use this data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   date_num = input(date,mmddyy11.);
   format date_num date9.;
   rename date_num=date date=date_string ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To fix the way you are creating the original dataset so that the variable is defined as a date to begin with you need to explain what you mean by the words "extract" and "file".&amp;nbsp; If you have a text file and you want to create a SAS dataset from it then use a data step with an INFILE statement and appropriate INPUT statements.&amp;nbsp; If you read the string from the text file use the MMDDYY informat to start with then the variable you create will have date values already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that in addition to being precise about what you mean by "extract" and "file" you should be precise about what you mean by "format".&amp;nbsp; The word FORMAT in SAS has a specific meaning that is different than they way you are using it.&amp;nbsp; SAS has only two types of variables, floating point numbers and fixed length character strings.&amp;nbsp; SAS stores DATE, TIME and DATETIME values as numbers. So a variable does not have a "date format".&amp;nbsp; Instead it contains date values.&amp;nbsp; You could attach a date type format to the variable so that the values display in a way that humans will recognize as a date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS a FORMAT is instructions for how to display values as text.&amp;nbsp; A numeric format (like the DATE format) displays numbers as text.&amp;nbsp; A character format displays character values as text.&amp;nbsp; SAS also has something called in an INFORMAT.&amp;nbsp; An informat converts text into values.&amp;nbsp; A numeric informat converts the text into a number (like the MMDDYY informat). A character informat converts text into character values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 16:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/825987#M326254</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-28T16:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/826001#M326265</link>
      <description>&lt;P&gt;Please post the code you use to read the file.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 16:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-format/m-p/826001#M326265</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-07-28T16:42:19Z</dc:date>
    </item>
  </channel>
</rss>

