<?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: Format text into sas date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914701#M360441</link>
    <description>&lt;P&gt;Did you actually mean 2020-11-30 to read as 30NOV2030 because that is a little challenging.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But here is what I would do to get the correct date format. 'd first input the text date as yymmdd10, and then change it to date9.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data test;&lt;/DIV&gt;&lt;DIV&gt;input date yymmdd10.;&lt;/DIV&gt;&lt;DIV&gt;infile datalines;&lt;/DIV&gt;&lt;DIV&gt;datalines;&lt;/DIV&gt;&lt;DIV&gt;2020-11-30&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data test2;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set test;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;fmt_Date = put(date, date9.);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Tue, 06 Feb 2024 14:49:03 GMT</pubDate>
    <dc:creator>rvikram</dc:creator>
    <dc:date>2024-02-06T14:49:03Z</dc:date>
    <item>
      <title>Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914664#M360426</link>
      <description>If i read text in say 2022-11-30 and i like to format to 30NOV2030, do i just add format date9. after the input statement say&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308480"&gt;@002&lt;/a&gt; startdate date9.&lt;BR /&gt;@010 endate date9.&lt;BR /&gt;@018 fruit $8.&lt;BR /&gt;</description>
      <pubDate>Tue, 06 Feb 2024 11:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914664#M360426</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-06T11:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914666#M360428</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;If i read text in say 2022-11-30 and i like to format to 30NOV2030, do i just add format date9. after the input statement say&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308480"&gt;@002&lt;/a&gt; startdate date9.&lt;BR /&gt;@010 endate date9.&lt;BR /&gt;@018 fruit $8.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please try it and see (&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 4&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please check for typos and correct them before you send your message, 2022-11-30 is not the same date as&amp;nbsp; 30NOV2030&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 11:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914666#M360428</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-06T11:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914682#M360434</link>
      <description>&lt;P&gt;The&amp;nbsp;&lt;STRONG&gt;IN&lt;/STRONG&gt;PUT statement uses&amp;nbsp;&lt;STRONG&gt;in&lt;/STRONG&gt;formats. Informats control how data is&amp;nbsp;&lt;EM&gt;read&lt;/EM&gt;, not how it is&amp;nbsp;&lt;EM&gt;displayed&lt;/EM&gt;. For the display, use formats in a FORMAT statement.&lt;/P&gt;
&lt;P&gt;So, in your INPUT, you have to use an informat which matches the way the dates come in. In a FORMAT statement, assign formats according to how you want the dates to look for you and other users.&lt;/P&gt;
&lt;P&gt;The informat for a date in YYYY-MM-DD notation is YYMMDD10. or E8601DA10.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 13:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914682#M360434</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-06T13:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914691#M360436</link>
      <description>Can i put&lt;BR /&gt;Input &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308480"&gt;@002&lt;/a&gt; statedate $10.&lt;BR /&gt;@009 enddate $10.&lt;BR /&gt;&lt;BR /&gt;Then later in a dara step put&lt;BR /&gt;Data test;&lt;BR /&gt;Set test0:&lt;BR /&gt;Format startdate date9.;&lt;BR /&gt;Format enddate date9.;&lt;BR /&gt;Run;</description>
      <pubDate>Tue, 06 Feb 2024 14:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914691#M360436</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-06T14:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914693#M360438</link>
      <description>&lt;P&gt;&lt;STRONG&gt;NO.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;SAS dates are numeric, counting the days from 1960-01-01. So you MUST read date values with the proper numeric informat, as I have already explained. Only then can you use any of the date formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 14:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914693#M360438</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-06T14:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914701#M360441</link>
      <description>&lt;P&gt;Did you actually mean 2020-11-30 to read as 30NOV2030 because that is a little challenging.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;But here is what I would do to get the correct date format. 'd first input the text date as yymmdd10, and then change it to date9.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data test;&lt;/DIV&gt;&lt;DIV&gt;input date yymmdd10.;&lt;/DIV&gt;&lt;DIV&gt;infile datalines;&lt;/DIV&gt;&lt;DIV&gt;datalines;&lt;/DIV&gt;&lt;DIV&gt;2020-11-30&lt;/DIV&gt;&lt;DIV&gt;;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;data test2;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set test;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;fmt_Date = put(date, date9.);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 06 Feb 2024 14:49:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914701#M360441</guid>
      <dc:creator>rvikram</dc:creator>
      <dc:date>2024-02-06T14:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914708#M360444</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;@002 startdate yymmdd10.
@010 endate  yymmdd10.
@018 fruit $8. 
....
;

format startdate enddate date9.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Something along those lines is what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The informats in the input statement need to match what the data looks like when read in.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To control what it looks like after, you can use a format statement. This can be in the same data step when the data is read or separate data step, I recommend the import data step if you want the format attached to the data. It can also be modified using proc datasets as well.&amp;nbsp;&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/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;If i read text in say 2022-11-30 and i like to format to 30NOV2030, do i just add format date9. after the input statement say&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308480"&gt;@002&lt;/a&gt; startdate date9.&lt;BR /&gt;@010 endate date9.&lt;BR /&gt;@018 fruit $8.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 15:38:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914708#M360444</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-06T15:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914720#M360450</link>
      <description>&lt;P&gt;Yes, if you want the dates to display in the style ddMMMyyyy then add a FORMAT statement to attach the format specification of DATE9. to the variables after the INPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But that is NOT what the code fragment you showed is doing. You appear to have modified the INPUT statement itself and changed the INFORMAT to use to read the strings in the text into date values.&amp;nbsp; Strings that look like YYYY-MM-DD cannot be read using the DATE informat.&amp;nbsp; You need to use the YYMMDD10. informat to read in string of length 10 with the date parts as numbers in Year Month_of_year Day_of_month order.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2024 16:21:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914720#M360450</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-06T16:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914724#M360452</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/416388"&gt;@HeatherNewton&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Can i put&lt;BR /&gt;Input &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/308480"&gt;@002&lt;/a&gt; statedate $10.&lt;BR /&gt;@009 enddate $10.&lt;BR /&gt;&lt;BR /&gt;Then later in a dara step put&lt;BR /&gt;Data test;&lt;BR /&gt;Set test0:&lt;BR /&gt;Format startdate date9.;&lt;BR /&gt;Format enddate date9.;&lt;BR /&gt;Run;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you read the string using the $ informat then you will create CHARACTER variables.&amp;nbsp; You cannot use a numeric format like DATE with a character variable.&amp;nbsp; You will first have to make a new numeric variable by using the INPUT() function to convert the character strings into date values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set test0:
  startdate_num = input(startdate,yymmdd10.);
  enddate_num = input(enddate,yymmdd10.);
  format startdate_num enddate_num date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are happy storing dates as character (perhaps you don't need to ever use them in comparisons or filtering; you only plan printing them) then since your character variables are of length $10 they are long enough to store the date strings in the ddMONyyyy style generated by DATE9.&amp;nbsp; (But not long enough to store the dd-MON-yyyy style generated by DATE11.)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set test0:
  startdate = put(input(startdate,yymmdd10.),date9.);
  enddate = put(input(enddate,yymmdd10.),date9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Feb 2024 16:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914724#M360452</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-06T16:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914833#M360507</link>
      <description>&lt;PRE class="language-sas"&gt;&lt;CODE&gt;data test;
  set test0:
  startdate = put(input(startdate,yymmdd10.),date9.);
  enddate = put(input(enddate,yymmdd10.),date9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;what if I want to use different name here, how to rename them back to original?&lt;/P&gt;
&lt;P&gt;data test;&lt;/P&gt;
&lt;P&gt;set test0;&lt;/P&gt;
&lt;P&gt;startdate1=input(statedate,yymmdd10.);&lt;/P&gt;
&lt;P&gt;format startdate1 date9.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;but actually I want startdate to be startdate1&lt;/P&gt;
&lt;P&gt;so possible to write like the below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test (drop startdate1);&lt;/P&gt;
&lt;P&gt;set test0;&lt;/P&gt;
&lt;P&gt;startdate1=input(statedate,yymmdd10.);&lt;/P&gt;
&lt;P&gt;format startdate1 date9.;&lt;/P&gt;
&lt;P&gt;rename startdate1=startdate;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 10:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914833#M360507</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-07T10:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914898#M360539</link>
      <description>&lt;P&gt;Test it and see.&lt;/P&gt;
&lt;PRE&gt;329  data test (drop=name1);
330    set sashelp.class;
331    name1 = name;
332    rename name1=name;
333  run;

WARNING: Variable name1 cannot be renamed to name because name already exists.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;You cannot name TESTDATE1 as TESTDATE because there is already a TESTDATE variable.&amp;nbsp; You will need to either RENAME that variable also.&amp;nbsp; Or DROP it.&lt;/P&gt;
&lt;PRE&gt;334  data test ;
335    set sashelp.class;
336    name1 = name;
337    rename name1=name;
338    drop name;
339  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;I have never had much use for using DROP=,RENAME=,KEEP= dataset options on the OUTPUT dataset for a simple data step that is only creating one dataset.&amp;nbsp; Seems much clearer to just use the actual DROP, RENAME or KEEP statements instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using it on the INPUT dataset makes more sense.&lt;/P&gt;
&lt;PRE&gt;345  data test ;
346    set sashelp.class(rename=(name=old_name));
347    name = old_name;
348    drop old_name;
349  run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST has 19 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2024 18:05:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914898#M360539</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-02-07T18:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914982#M360562</link>
      <description>Thanks! Got it now. If i have many variable like name that i need to first rename and assign, how to add in rename statement in the set dataset line..</description>
      <pubDate>Thu, 08 Feb 2024 00:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914982#M360562</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2024-02-08T00:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Format text into sas date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914991#M360566</link>
      <description>Or just read it in correctly the first time since you are doing the input step.</description>
      <pubDate>Thu, 08 Feb 2024 02:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Format-text-into-sas-date/m-p/914991#M360566</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-08T02:05:36Z</dc:date>
    </item>
  </channel>
</rss>

