<?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: converting 7 digit date to regular date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397838#M96174</link>
    <description>&lt;P&gt;The&amp;nbsp;B8601CI. informat can read date strings in the format CYYMMDDHHMMSS, but the meaning of the Century value is a little different. 0 means 1900 and 1 means 2000. &amp;nbsp;So just subtract 1,000,000 from your number before converting it to a string and addting the zeros for the time part. Use the DATEPART() function to convert back to a date variable instead of a datetime variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date_ ;
cards;
1980901
1990831
2011011
2130801
;
run;

data want ;
  set have ;
  date = datepart(input(put(date_-1000000,z7.)||'000000',B8601CI.));
  format date yymmdd10. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 185px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15330i8AF564043A4AABA9/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Sep 2017 17:24:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-09-21T17:24:37Z</dc:date>
    <item>
      <title>converting 7 digit date to regular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397814#M96164</link>
      <description>&lt;P&gt;Good Afternoon everyone! So, I have got these dates which look like these:-&lt;/P&gt;
&lt;P&gt;1980901, 1990831, 2011011, 2130801&lt;/P&gt;
&lt;P&gt;but which mean actually 19980901, 19990831, 20011011, 20130801&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically you need to replace first digit by 19 if the first digit is 1 and by 20 if the first digit is 2. I tried the following code, and not sure what im doing incorrect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_ ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;1980901&lt;/P&gt;
&lt;P&gt;1990831&lt;/P&gt;
&lt;P&gt;2011011&lt;/P&gt;
&lt;P&gt;2130801&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;run&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;LENGTH&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; DATE1 $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt; ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; substr(date_, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date1 = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;19&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;||substr(date_, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;ELSE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;IF&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; substr(date_, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date1 = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;20&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;||substr(date_, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;RUN&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 16:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397814#M96164</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-09-21T16:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: converting 7 digit date to regular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397817#M96165</link>
      <description>&lt;P&gt;Date_ as a numeric variable so use SUBSTRN instead of SUBSTR.&lt;/P&gt;
&lt;P&gt;The variables you're creating are character and SUBSTR returns a character value so you need quotes. Same with CAT/||, it's character so it needs quotes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Last but not least, please use the code editor to enter your code and format it for legibility in the future.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a worked solution and an example of creating an actual SAS date out of the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input date_;
	cards;
1980901
1990831
2011011
2130801
;
run;

data want;
	set test;
	LENGTH DATE1 $8;

	if substrn(date_, 1, 1)='1' then
		date1='19'||substrn(date_, 2);
	ELSE IF substrn(date_, 1, 1)='2' then
		date1='20'||substrn(date_, 2);
	sas_date=input(put(date1, 8.), yymmdd8.);
	format sas_date date9.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 16:14:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397817#M96165</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-21T16:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: converting 7 digit date to regular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397820#M96168</link>
      <description>&lt;P&gt;I have to say that I've seen a fair&amp;nbsp;number of mangled dates but this is new way to me.&lt;/P&gt;
&lt;P&gt;Are all of your dates 7 characters or is this only for some of them in the data?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 16:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397820#M96168</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-21T16:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: converting 7 digit date to regular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397835#M96172</link>
      <description>&lt;P&gt;No, they are all 7 digits from what I know. They are formatted as number though.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 17:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397835#M96172</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-09-21T17:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: converting 7 digit date to regular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397838#M96174</link>
      <description>&lt;P&gt;The&amp;nbsp;B8601CI. informat can read date strings in the format CYYMMDDHHMMSS, but the meaning of the Century value is a little different. 0 means 1900 and 1 means 2000. &amp;nbsp;So just subtract 1,000,000 from your number before converting it to a string and addting the zeros for the time part. Use the DATEPART() function to convert back to a date variable instead of a datetime variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date_ ;
cards;
1980901
1990831
2011011
2130801
;
run;

data want ;
  set have ;
  date = datepart(input(put(date_-1000000,z7.)||'000000',B8601CI.));
  format date yymmdd10. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 185px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15330i8AF564043A4AABA9/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 17:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397838#M96174</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-21T17:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: converting 7 digit date to regular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397852#M96184</link>
      <description>&lt;P&gt;Thanks Reeza. One thing I noticed in your code was having additonal put inside the input function-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sas_date=input(put(date1, 8.), yymmdd8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token punctuation"&gt;But if I remove that and use just&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT size="3"&gt;&lt;CODE class=" language-sas"&gt;sas_date=input(date1, yymmdd8.);&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;it works fine too.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;So, not sure whats the purpose of put function here?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 17:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397852#M96184</guid>
      <dc:creator>devsas</dc:creator>
      <dc:date>2017-09-21T17:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: converting 7 digit date to regular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397884#M96193</link>
      <description>&lt;P&gt;It's likely possible I made a mistake.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If date1 is numeric but in the format you want, ie 20170101, then you would use PUT. If it's already character you don't need the PUT.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2017 19:04:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/converting-7-digit-date-to-regular-date/m-p/397884#M96193</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-21T19:04:29Z</dc:date>
    </item>
  </channel>
</rss>

