<?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: DATA STEP change date format but year changes on its own in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578451#M164070</link>
    <description>&lt;P&gt;Yeah I tried both and still no good:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char_date = input(SVSTDTC, date15.);
format char_date date9. ;


char_date = input(SVSTDTC, date15.);
format char_date date15. ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 01 Aug 2019 15:06:59 GMT</pubDate>
    <dc:creator>jerrylshen</dc:creator>
    <dc:date>2019-08-01T15:06:59Z</dc:date>
    <item>
      <title>DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578440#M164061</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Imported SAS file named "sv1"

data sv;
	set sv1 ;
	by subject;
	char_date = input(SVSTDTC,date8.); 
	format char_date date9. ;
run;

proc print data=sv;
run;
 &lt;BR /&gt;/*  Edit: I also tried these but no good still:&lt;BR /&gt; *  char_date = input(SVSTDTC, date15.);&lt;BR /&gt; *  format char_date date15. ;&lt;BR /&gt;&amp;nbsp;*&lt;BR /&gt; *  char_date = input(SVSTDTC, date15.);&lt;BR /&gt; *  format char_date date9. ;&lt;BR /&gt;&amp;nbsp;*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot (124).png" style="width: 436px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31465i60C2BE7C393232D0/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot (124).png" alt="Screenshot (124).png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to find the days difference using INTCK, but it says that the date&amp;nbsp;&lt;CODE class=" language-sas"&gt;SVSTDTC has to numeric, so I'm trying to reformat&amp;nbsp;SVSTDTC. But the year output is all messed up for some reason.&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Any help?&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;Thanks&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:08:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578440#M164061</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-01T15:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578442#M164062</link>
      <description>&lt;P&gt;Your incoming date string is 10 characters long.&amp;nbsp; But you read it with an informat that reads only 8 characters.&amp;nbsp; Try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char_date = input(SVSTDTC,date10.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:55:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578442#M164062</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-01T14:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578443#M164063</link>
      <description>&lt;P&gt;Why would you name a variable that has a numeric value as CHAR_DATE?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why would you use a length of 8 with the DATE informat? It takes 9 characters to show a date with full year.&amp;nbsp; DDMONYYYY.&amp;nbsp; With only 2 digit year then it takes 7 characters. If you read only 8 characters you have lost the least significant digit of the year.&amp;nbsp; Not sure how that would cause the issue you are seeing instead of an error.&amp;nbsp; 01AUG201 is not a valid date.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 14:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578443#M164063</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-01T14:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578445#M164065</link>
      <description>Nope, changing it to "char_date = input(SVSTDTC, date10.);" didn't fix it, still 2020 as year:'(</description>
      <pubDate>Thu, 01 Aug 2019 14:59:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578445#M164065</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-01T14:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578446#M164066</link>
      <description>&lt;P&gt;Looks like some of your incoming date strings are even longer than 10 characters.&amp;nbsp; Play with it.&amp;nbsp; Try date11. or date12.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578446#M164066</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-08-01T15:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578447#M164067</link>
      <description>I copy/pasted code from other solutions when doing this, but good point, I'll change the name afterwards.&lt;BR /&gt;&lt;BR /&gt;I tried "char_date = input(SVSTDTC, date9.);" but still no good:/</description>
      <pubDate>Thu, 01 Aug 2019 15:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578447#M164067</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-01T15:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578449#M164068</link>
      <description>&lt;P&gt;We cannot tell what actual values your character variable has from Polaroids of your screen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;remove leading spaces from the string&lt;/LI&gt;
&lt;LI&gt;Use a longer width on the informat&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input string $char20.;
  date1=input(string,date11.);
  date2=input(left(string),date11.);
  format string $char20. date: date9.;
*---+----0----+----0;
cards;
1/JAN/2017
 2/JAN/2017
  3/JAN/2017
   4/JAN/2017
    5/JAN/2017
     6/JAN/2017
      7/JAN/2017
       8/JAN/2017
        9/JAN/2017
         1/JAN/2017
;

proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    string                      date1        date2

  1    1/JAN/2017              01JAN2017    01JAN2017
  2     2/JAN/2017             02JAN2017    02JAN2017
  3      3/JAN/2017                    .    03JAN2017
  4       4/JAN/2017           04JAN2020    04JAN2017
  5        5/JAN/2017          05JAN2002    05JAN2017
  6         6/JAN/2017                 .    06JAN2017
  7          7/JAN/2017                .    07JAN2017
  8           8/JAN/2017               .    08JAN2017
  9            9/JAN/2017              .    09JAN2017
 10             1/JAN/2017             .    01JAN2017&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578449#M164068</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-01T15:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578450#M164069</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char_date = input(compress(svstdtc,'/'),date10.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578450#M164069</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-01T15:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578451#M164070</link>
      <description>&lt;P&gt;Yeah I tried both and still no good:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char_date = input(SVSTDTC, date15.);
format char_date date9. ;


char_date = input(SVSTDTC, date15.);
format char_date date15. ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578451#M164070</guid>
      <dc:creator>jerrylshen</dc:creator>
      <dc:date>2019-08-01T15:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578452#M164071</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;char_date = input(compress(svstdtc,'/'),date10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That won't fix it if the issue is leading spaces.&amp;nbsp; Also there is no need to remove the slashes as the DATE informat works fine with slashes as the delimiter.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578452#M164071</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-01T15:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578462#M164076</link>
      <description>&lt;P&gt;You are actually hiding you data by showing pictures. Pictures do not show values.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note:&lt;/P&gt;
&lt;PRE&gt;data example;
   svstdtc= '1/Jan/2019';
   char_date1 = input(SVSTDTC,date8.);
   char_date2 = input(SVSTDTC,date10.);
   format char_date1 char_date2 date9. ;
run;
ods listing;
proc print;run;
ods listing close;&lt;/PRE&gt;
&lt;P&gt;Creates&lt;/P&gt;
&lt;PRE&gt;                         char_        char_
Obs     svstdtc          date1        date2

 1     1/Jan/2019    01JAN2020    01JAN2019

&lt;/PRE&gt;
&lt;P&gt;When you read&lt;/P&gt;
&lt;P&gt;1/Jan/2019 with date8 format it stops reading&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^&lt;/P&gt;
&lt;P&gt;And so treats the input string as if the 20 were the last 2 digits as 2020 because it looks similar to date7 : 01JAN20&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;10/Jan/2019 gets treated as 10Jan2002 because the 8th character is the 2 and so you have told SAS that is entire "year" value it should use for the input and again less than a 4 year value is treated as 2 digits, i.e. 02.&lt;/P&gt;
&lt;P&gt;DATE10 will not work with 10/Jan/2019 because that would attempt to use a 3 digit year and that just isn't allowed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest:&lt;/P&gt;
&lt;PRE&gt;   if length(svstdtc)=10 then char_date1 = input(SVSTDTC,date10.);
   else if length(svstdtc)=11 then char_date1 = input(SVSTDTC,date11.);
&lt;/PRE&gt;
&lt;P&gt;If you have some with actual 2 digit years then you need to add in cases for lengths of 8 and 9 as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578462#M164076</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-01T15:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: DATA STEP change date format but year changes on its own</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578474#M164080</link>
      <description>&lt;P&gt;Note that there is no need to check length of input string. The DATE informat supports widths up to 32.&amp;nbsp; The INPUT function does not mind if the string is shorter than the width of the informat being used.&lt;/P&gt;
&lt;PRE&gt;526   data test;
527     dt=input('01jan2019',date32.);
528     format dt date9.;
529     put dt=;
530   run;

dt=01JAN2019
&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 15:28:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DATA-STEP-change-date-format-but-year-changes-on-its-own/m-p/578474#M164080</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-08-01T15:28:02Z</dc:date>
    </item>
  </channel>
</rss>

