<?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 formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376045#M90199</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a sample dataset as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format ref_date_1	ref_date_2 mmddyy10. clm_date1	clm_date2 datetime16.;
informat ref_date_1	ref_date_2 mmddyy10. clm_date1	clm_date2 datetime16.;
input claim_id	ref_date_1	ref_date_2	clm_date1	clm_date2;
datalines;
1123524	5/12/2017	4/18/2012	05MAY17:17:09:00	26MAY17:13:45:00
1123524	5/13/2017	4/19/2012	16MAY17:17:11:50	23MAY17:17:23:00
1123524	5/14/2017	4/20/2012	05MAY17:17:09:01	04MAY17:19:40:00
1123524	5/15/2017	4/21/2012	16MAY17:17:11:51	26MAY17:13:45:01
1123524	5/16/2017	4/22/2012	05MAY17:17:09:02	23MAY17:17:23:01
1123524	5/17/2017	4/23/2012	16MAY17:17:11:52	04MAY17:19:40:01
1123524	5/18/2017	4/24/2012	05MAY17:17:09:03	26MAY17:13:45:02
1123524	5/19/2017	4/25/2012	16MAY17:17:11:53	23MAY17:17:23:02
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need all these dates converted to mmddyy10. format and store them in new variables. The problem is that I have many variables like these and I don't know which variable has which format. What I can see is mmddyy10. and datetime16. are most prevalent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried this below but this is not feasible because first there are many variable and second I don't know which has what format. Is there any way I can read all variables with some informat?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=ref_date_1 ref_date_2 clm_date1 clm_date2);
	format ref_date_1_new ref_date_2_new clm_date1_new clm_date2_new mmddyy10.;
	set have;
	ref_date_1_new = ref_date_1;
	ref_date_2_new = ref_date_2;
	clm_date1_new = datepart(clm_date1);
	clm_date2_new = datepart(clm_date2);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is appreciated.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jul 2017 15:03:05 GMT</pubDate>
    <dc:creator>PBsas</dc:creator>
    <dc:date>2017-07-14T15:03:05Z</dc:date>
    <item>
      <title>date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376045#M90199</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a sample dataset as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format ref_date_1	ref_date_2 mmddyy10. clm_date1	clm_date2 datetime16.;
informat ref_date_1	ref_date_2 mmddyy10. clm_date1	clm_date2 datetime16.;
input claim_id	ref_date_1	ref_date_2	clm_date1	clm_date2;
datalines;
1123524	5/12/2017	4/18/2012	05MAY17:17:09:00	26MAY17:13:45:00
1123524	5/13/2017	4/19/2012	16MAY17:17:11:50	23MAY17:17:23:00
1123524	5/14/2017	4/20/2012	05MAY17:17:09:01	04MAY17:19:40:00
1123524	5/15/2017	4/21/2012	16MAY17:17:11:51	26MAY17:13:45:01
1123524	5/16/2017	4/22/2012	05MAY17:17:09:02	23MAY17:17:23:01
1123524	5/17/2017	4/23/2012	16MAY17:17:11:52	04MAY17:19:40:01
1123524	5/18/2017	4/24/2012	05MAY17:17:09:03	26MAY17:13:45:02
1123524	5/19/2017	4/25/2012	16MAY17:17:11:53	23MAY17:17:23:02
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need all these dates converted to mmddyy10. format and store them in new variables. The problem is that I have many variables like these and I don't know which variable has which format. What I can see is mmddyy10. and datetime16. are most prevalent.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried this below but this is not feasible because first there are many variable and second I don't know which has what format. Is there any way I can read all variables with some informat?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=ref_date_1 ref_date_2 clm_date1 clm_date2);
	format ref_date_1_new ref_date_2_new clm_date1_new clm_date2_new mmddyy10.;
	set have;
	ref_date_1_new = ref_date_1;
	ref_date_2_new = ref_date_2;
	clm_date1_new = datepart(clm_date1);
	clm_date2_new = datepart(clm_date2);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your help is appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376045#M90199</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-07-14T15:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376050#M90201</link>
      <description>&lt;P&gt;You might want to explore&amp;nbsp;reading them as strings first then use prxmatch to check the pattern so you could convert them with the proper informat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Usage of prxmatch can be found here&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n0bj9p4401w3n9n1gmv6tf**bleep**9m.htm" target="_self"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n0bj9p4401w3n9n1gmv6tf**bleep**9m.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376050#M90201</guid>
      <dc:creator>milts</dc:creator>
      <dc:date>2017-07-14T15:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376053#M90202</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/53881"&gt;@PBsas&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need all these dates converted to mmddyy10. format and store them in new variables. The problem is that I have many variables like these and I don't know which variable has which format. What I can see is mmddyy10. and datetime16. are most prevalent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your help is appreciated.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="4"&gt;&lt;STRONG&gt;WHY?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;You can specify the Format to use at any given time.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;If you want to convert datetime to dates that's one thing but see:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="2"&gt;data _null_;
   set have;
   put ref_date_1= mmddyy10. ref_date_1= date9. ref_date_1= yyq.;
run;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT size="2"&gt;If I want the date to be used one way in one procedure and differently in an other procedure then just specify the format for each procedure:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;proc print data=have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var ref_date_1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format ref_date_ ddmmyy10.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;proc print data=have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var ref_date_1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; format ref_date_ worddate.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376053#M90202</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-14T15:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376055#M90203</link>
      <description>&lt;P&gt;I need to convert datetime to date. I have many variables and I don't know which has datetime and which has date in original data set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376055#M90203</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-07-14T15:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376063#M90206</link>
      <description>&lt;P&gt;I have never used prxmatch before. Looks like the link is broken. I will take a look if prxmatch can be used. Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376063#M90206</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-07-14T15:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376089#M90215</link>
      <description>&lt;P&gt;If you know something about the years involved (such as they are all within the past 30 years or so), this approach would work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 1: &amp;nbsp;Read in all variables as dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Step 2: &amp;nbsp;Convert the datetimes&amp;nbsp;by having SAS examine the values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if ref_date1 &amp;gt; '01jan2050'd then ref_date1 = datepart(ref_date1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 16:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/376089#M90215</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-14T16:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/377139#M90540</link>
      <description>&lt;P&gt;All my dates are within past 4-5 years so this will work. Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2017 21:13:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-formats/m-p/377139#M90540</guid>
      <dc:creator>PBsas</dc:creator>
      <dc:date>2017-07-18T21:13:43Z</dc:date>
    </item>
  </channel>
</rss>

