<?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: How to create two different date formats in one dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814787#M81819</link>
    <description>&lt;P&gt;You really should show LOG entries when code does not work as expected.&lt;/P&gt;
&lt;P&gt;Please compare this to your code:&lt;/P&gt;
&lt;PRE&gt;data A;
format my_date date7. d_date mmddyy10. ;
input my_date :date7. d_date :mmddyy10.  ;
datalines;
08JAN19 10/21/2005 
26JUN20 12/12/2010
05DEC20 03/29/2009
04OCT13 11/11/2010
;
run;&lt;/PRE&gt;
&lt;P&gt;When you specify an informat without the : modifier then a variable is read from the position of the input column that ends the last element read. Your code was attempting to read starting at the space after the 9 in 08JAN19 and was forced to read exactly 10 characters. So characters attempted to read as the first mmddyy value were " 10/21/200" 3-digit years are right out from the informat perspective. The : modifier says in effect "start reading where the next non-space value is".&lt;/P&gt;
&lt;P&gt;Note that this code would also work:&lt;/P&gt;
&lt;PRE&gt;data A;
format my_date date7. d_date mmddyy10. ;
input my_date date7. d_date mmddyy10.  ;
datalines;
08JAN1910/21/2005 
26JUN2012/12/2010
05DEC2003/29/2009
04OCT1311/11/2010
;
run;&lt;/PRE&gt;
&lt;P&gt;As the first 7 columns are read for My_date and then columns 8 through 17 are read for d_date.&lt;/P&gt;</description>
    <pubDate>Mon, 23 May 2022 20:08:55 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-05-23T20:08:55Z</dc:date>
    <item>
      <title>How to create two different date formats in one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814755#M81817</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to create two different date formats so I can convert them into the same format for further analysis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data A;&lt;BR /&gt;format my_date date7. d_date mmddyy10. ;&lt;BR /&gt;input my_date date7.&amp;nbsp;d_date mmddyy10.&amp;nbsp; ;&lt;BR /&gt;datalines;&lt;BR /&gt;08JAN19 10/21/2005&lt;BR /&gt;26JUN20 12/12/2010&lt;BR /&gt;05DEC20 03/29/2009&lt;BR /&gt;04OCT13 11/11/2010&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The table below is what I wanted but the code above is not giving me the expected result. What am I doing wrong?&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;my_date&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;d_date&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;08JAN19&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;12/12/2010&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;26JUN20&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;03/29/2009&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;05DEC20&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;11/11/2010&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;04OCT13&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;12/12/2010&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Mon, 23 May 2022 18:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814755#M81817</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2022-05-23T18:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to create two different date formats in one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814757#M81818</link>
      <description>&lt;P&gt;Change your INPUT statement to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input my_date date7. +1 d_date mmddyy10.  ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to create two different date formats so I can convert them into the same format for further analysis.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This really doesn't make sense. Dates can be analyzed in any format, variable 1 can be format 1 and variable 2 can be format 2, and they can even be unformatted, and the results will be the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 18:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814757#M81818</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-23T18:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create two different date formats in one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814787#M81819</link>
      <description>&lt;P&gt;You really should show LOG entries when code does not work as expected.&lt;/P&gt;
&lt;P&gt;Please compare this to your code:&lt;/P&gt;
&lt;PRE&gt;data A;
format my_date date7. d_date mmddyy10. ;
input my_date :date7. d_date :mmddyy10.  ;
datalines;
08JAN19 10/21/2005 
26JUN20 12/12/2010
05DEC20 03/29/2009
04OCT13 11/11/2010
;
run;&lt;/PRE&gt;
&lt;P&gt;When you specify an informat without the : modifier then a variable is read from the position of the input column that ends the last element read. Your code was attempting to read starting at the space after the 9 in 08JAN19 and was forced to read exactly 10 characters. So characters attempted to read as the first mmddyy value were " 10/21/200" 3-digit years are right out from the informat perspective. The : modifier says in effect "start reading where the next non-space value is".&lt;/P&gt;
&lt;P&gt;Note that this code would also work:&lt;/P&gt;
&lt;PRE&gt;data A;
format my_date date7. d_date mmddyy10. ;
input my_date date7. d_date mmddyy10.  ;
datalines;
08JAN1910/21/2005 
26JUN2012/12/2010
05DEC2003/29/2009
04OCT1311/11/2010
;
run;&lt;/PRE&gt;
&lt;P&gt;As the first 7 columns are read for My_date and then columns 8 through 17 are read for d_date.&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 20:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814787#M81819</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-05-23T20:08:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to create two different date formats in one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814789#M81820</link>
      <description>&lt;P&gt;That is not the output I get for that code.&lt;/P&gt;
&lt;PRE&gt;18  data A;
119  format my_date date7. d_date mmddyy10. ;
120  input my_date date7. d_date mmddyy10.  ;
121  datalines;

NOTE: Invalid data for d_date in line 122 8-17.
RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6--
122        08JAN19 10/21/2005
my_date=08JAN19 d_date=. _ERROR_=1 _N_=1
NOTE: Invalid data for d_date in line 123 8-17.
123        26JUN20 12/12/2010
my_date=26JUN20 d_date=. _ERROR_=1 _N_=2
NOTE: Invalid data for d_date in line 124 8-17.
124        05DEC20 03/29/2009
my_date=05DEC20 d_date=. _ERROR_=1 _N_=3
NOTE: Invalid data for d_date in line 125 8-17.
125        04OCT13 11/11/2010
my_date=04OCT13 d_date=. _ERROR_=1 _N_=4
NOTE: The data set WORK.A has 4 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


126  ;
&lt;/PRE&gt;
&lt;P&gt;Try reading the data in LIST mode instead of fixed format mode.&lt;/P&gt;
&lt;P&gt;Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data A;
  input my_date :date. d_date :mmddyy.  ;
  format my_date d_date yymmdd10.;
datalines;
08JAN19 10/21/2005
26JUN20 12/12/2010
05DEC20 03/29/2009
04OCT13 11/11/2010
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is no good reason to attach different formats to dates in the same dataset.&amp;nbsp; That will just confuse you.&amp;nbsp; SAS does not care what format you use to display the dates.&amp;nbsp; The format used to display a value does not change the value that is stored. Also avoid using either M-D-Y or D-M-Y order to display dates, either order you select will confuse half of your audience.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs       my_date        d_date

 1     2019-01-08    2005-10-21
 2     2020-06-26    2010-12-12
 3     2020-12-05    2009-03-29
 4     2013-10-04    2010-11-11
&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 May 2022 20:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-two-different-date-formats-in-one-dataset/m-p/814789#M81820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-23T20:17:39Z</dc:date>
    </item>
  </channel>
</rss>

