<?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: Changing Character-Type Column to Numeric-Type (Date-Group) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868266#M342978</link>
    <description>&lt;P&gt;That would be January 11, 2023. The format of the values are 'year-month-day'.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Apr 2023 14:37:59 GMT</pubDate>
    <dc:creator>u787bruw</dc:creator>
    <dc:date>2023-04-05T14:37:59Z</dc:date>
    <item>
      <title>Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868263#M342976</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;* Create dataset;
data test;
	input var1 $10.;
	datalines;
	2023324
	2023324
	2023324
	2023324
	2023324
	20231230
	;
run;

* Alter data;
data test;
	set test;
	/* Modify timestamp format for 'CREATE_TIMESTAMP' */
	YEAR	= SUBSTR(var1, 1, 4);
	MONTH 	= SUBSTR(var1, 5, 1);
	DAY 	= SUBSTR(var1, 6, 2);
	FORM_CREATE_TIMESTAMP = CATS(YEAR, '-', MONTH, '-', DAY);
	DATE_CREATE_TIMESTAMP = INPUT(FORM_CREATE_TIMESTAMP, YYMMDD9.);
	FORMAT DATE_CREATE_TIMESTAMP YYMMDD10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have a column in a SAS dataset that is a 'character-type' and the values look something like '2020213'. All the values appear in the format, YYYYMDD, so I am concerned that if I convert the column like I did in the code above that it will screw up the values that have double-digit months or single-digit days (which it did) in my test above. How can I convert the values so that they look something more like:&lt;BR /&gt;'2022320' --&amp;gt; '2022-03-20'&lt;/P&gt;&lt;P&gt;'2022123' --&amp;gt; '2022-12-3'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have fiddled around with doing something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;CHAR_DATE_STRIPPED = STRIP(CHAR_DATE);
DATE1 = INPUT(CHAR_DATE_STRIPPED, YYMMDD8.);
FORMAT DATE1 YYMMDD9.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But I have gotten zero luck. The values are coming out as "."&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 14:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868263#M342976</guid>
      <dc:creator>u787bruw</dc:creator>
      <dc:date>2023-04-05T14:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868264#M342977</link>
      <description>You cannot with any certainty. &lt;BR /&gt;&lt;BR /&gt;Is 2023111 &lt;BR /&gt;January 11, 2023 or November 1, 2023?</description>
      <pubDate>Wed, 05 Apr 2023 14:36:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868264#M342977</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-05T14:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868266#M342978</link>
      <description>&lt;P&gt;That would be January 11, 2023. The format of the values are 'year-month-day'.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 14:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868266#M342978</guid>
      <dc:creator>u787bruw</dc:creator>
      <dc:date>2023-04-05T14:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868270#M342981</link>
      <description>&lt;P&gt;Why did you decide to divide the three ones into 11/1 instead of 1/11 ?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 14:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868270#M342981</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-05T14:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868273#M342983</link>
      <description>&lt;P&gt;I am sorry, but I do not quite understand your question. Hopefully I can try to answer it, but the data I am working on is not created by me. The example I just gave above mimics the data I am working on&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 14:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868273#M342983</guid>
      <dc:creator>u787bruw</dc:creator>
      <dc:date>2023-04-05T14:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868274#M342984</link>
      <description>&lt;P&gt;How do you know if a string like 2022123 should be treated as 2022-1-23 or 2022-12-3.&amp;nbsp; Either meaning is possible.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have extra information that can help you make a choice?&amp;nbsp; For example do you know the day of the month should never be more than one digit?&amp;nbsp; Or is there some other date field you can use to compate it to?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where did these strings come from?&amp;nbsp; What process was used to create them?&amp;nbsp; Can you get at the original data instead?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 14:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868274#M342984</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-05T14:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868275#M342985</link>
      <description>&lt;P&gt;Ah okay, now I understand the question. I know the data is treated as year-month-day because it is in the same sort of format as other columns that are numeric-type, meaning that they are 'YYYY-MM-DD'. I would like to just copy those columns into this, but the problem arises if the the data is not exactly the same. The dates could be one-day off for example.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 14:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868275#M342985</guid>
      <dc:creator>u787bruw</dc:creator>
      <dc:date>2023-04-05T14:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868276#M342986</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441184"&gt;@u787bruw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ah okay, now I understand the question. I know the data is treated as year-month-day because it is in the same sort of format as other columns that are numeric-type, meaning that they are 'YYYY-MM-DD'. I would like to just copy those columns into this, but the problem arises if the the data is not exactly the same. The dates could be one-day off for example.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441184"&gt;@u787bruw&lt;/a&gt;&amp;nbsp;As far as I can see, you have not answered&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;'s question. It seems he doesn't understand the meaning of&amp;nbsp;&lt;SPAN&gt;2022123, nor do I, and your reply doesn't shed any additional light on the matter. What is the date associated with 2022123?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 15:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868276#M342986</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-05T15:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868277#M342987</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441184"&gt;@u787bruw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ah okay, now I understand the question. I know the data is treated as year-month-day because it is in the same sort of format as other columns that are numeric-type, meaning that they are 'YYYY-MM-DD'. I would like to just copy those columns into this, but the problem arises if the the data is not exactly the same. The dates could be one-day off for example.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Copy?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert a string of digits in the style YYYYMMDD into a DATE you can use the YYMMDD informat. Once you have date value you can use any of the many date formats to have the number display in a way that humans will recognize as a date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datevar=input(stringvar,yymmdd10.);
format datevar yymmdd10.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if the digits strings do not represent an actual date, 20223456 for example, ; or are ambiguous about what date they represnet, 2022123, for example, then you need more information to convert them.&lt;/P&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>Wed, 05 Apr 2023 15:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868277#M342987</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-04-05T15:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868287#M342989</link>
      <description>&lt;P&gt;Your character input values are not consistent, they range between lengths 7 and 8.&amp;nbsp; so it they were the same you could use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile datalines;
input var1 $;
	ymd=input(var1,yymmdd8.);
format ymd yymmdd10.;

datalines;
20230324
20231124
20231024
20230924
20230624
20231230
;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1680708062907.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82362i1532B2048A403652/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1680708062907.png" alt="ghosh_0-1680708062907.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 15:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868287#M342989</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2023-04-05T15:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868289#M342990</link>
      <description>In case the data consists of inconsistent lengths, then check out this solution:&lt;BR /&gt; &lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/25213096/changing-date-formats-to-yymmdd8-in-sas-for-date-calculations" target="_blank"&gt;https://stackoverflow.com/questions/25213096/changing-date-formats-to-yymmdd8-in-sas-for-date-calculations&lt;/A&gt;</description>
      <pubDate>Wed, 05 Apr 2023 15:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868289#M342990</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2023-04-05T15:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868296#M342992</link>
      <description>&lt;P&gt;So the days have leading zeroes?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would Nov 1, 2023 be in the data?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 15:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868296#M342992</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-05T15:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Character-Type Column to Numeric-Type (Date-Group)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868297#M342993</link>
      <description>Not one day off, months off if you cannot differentiate between the days/months.</description>
      <pubDate>Wed, 05 Apr 2023 15:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-Character-Type-Column-to-Numeric-Type-Date-Group/m-p/868297#M342993</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-04-05T15:53:14Z</dc:date>
    </item>
  </channel>
</rss>

