<?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 change date character string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443411#M110932</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have date character strings that I need to change to numeric dates.&amp;nbsp; The values are either YYYY or YYYY-MM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATES&lt;/P&gt;
&lt;P&gt;2016&lt;/P&gt;
&lt;P&gt;2015&lt;/P&gt;
&lt;P&gt;2015-11&lt;/P&gt;
&lt;P&gt;2015-10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;since they are different format types how can I change them to numeric?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code leaves YYYY-MM - actually all values null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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; length(startc)=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;7&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; startn=input(startc,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;yymmd.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Help appreciated!!&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Mar 2018 16:46:32 GMT</pubDate>
    <dc:creator>jenim514</dc:creator>
    <dc:date>2018-03-07T16:46:32Z</dc:date>
    <item>
      <title>change date character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443411#M110932</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have date character strings that I need to change to numeric dates.&amp;nbsp; The values are either YYYY or YYYY-MM&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATES&lt;/P&gt;
&lt;P&gt;2016&lt;/P&gt;
&lt;P&gt;2015&lt;/P&gt;
&lt;P&gt;2015-11&lt;/P&gt;
&lt;P&gt;2015-10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;since they are different format types how can I change them to numeric?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code leaves YYYY-MM - actually all values null.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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; length(startc)=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;7&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; startn=input(startc,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;yymmd.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Help appreciated!!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 16:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443411#M110932</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2018-03-07T16:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: change date character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443419#M110934</link>
      <description>&lt;P&gt;You have to realize that dates refer to a specific day in SAS.&amp;nbsp; Converting 2016 to a date, for example, might mean getting January 1, 2016 as the result.&amp;nbsp; Converting 2015-11 might mean getting November 1, 2015 as a result.&amp;nbsp; At any rate, this can be done easily with one statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;datevar = input( trim(dates) || '-01-01', yymmdd10.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would probably want to add a FORMAT statement, so that DATEVAR looks like a date when it prints.&amp;nbsp; Pick any format you would like, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;format datevar date9.;&lt;/P&gt;
&lt;P&gt;format datevar yymmdd10.;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 17:04:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443419#M110934</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-07T17:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: change date character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443424#M110937</link>
      <description>&lt;P&gt;Isn't there a way to just keep 2016 as just a numeric year&amp;nbsp;2016 with out converting it to an actual&amp;nbsp;date(with a month and day), and have the 2016-10 converted to a numeric date yymm date?&amp;nbsp; It doesn't have to be an actual date format I guess, just numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 17:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443424#M110937</guid>
      <dc:creator>jenim514</dc:creator>
      <dc:date>2018-03-07T17:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: change date character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443430#M110940</link>
      <description>&lt;P&gt;If you want to use just one variable to hold the numeric value, that variable will have a format so that it prints looking like a date.&amp;nbsp; There is a way (a complex way) to design a format that could print in 3 different forms depending on the size of the variable.&amp;nbsp; So you could define a format that would print numbers below 3000 in 4 digits, for example, but numbers above 3000 in a different form.&amp;nbsp; To do that, you would need to know something about the values that your dates take on, and whether there would be a conflict.&amp;nbsp; For example, dates in the 1960s get&amp;nbsp;stored internally as integers below 3000 (mostly)&amp;nbsp;and the format might not be possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simpler would be to keep both variables.&amp;nbsp; Print the character version that you already have when that is appropriate, and recognize that the numeric dates represent a particular day.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 17:37:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443430#M110940</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-03-07T17:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: change date character string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443432#M110941</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/59697"&gt;@jenim514&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Isn't there a way to just keep 2016 as just a numeric year&amp;nbsp;2016 with out converting it to an actual&amp;nbsp;date(with a month and day), and have the 2016-10 converted to a numeric date yymm date?&amp;nbsp; It doesn't have to be an actual date format I guess, just numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you want this numeric to sort properly? 2016 would come way before 201511 as a numeric. What about the values that have a complete date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should describe exactly how you intend to use this not-a-date field later to get better suggestions. Though if anything will involve grouping by year or quarter or month or determining intervals between values then a date value is likely the best way to go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Mar 2018 17:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/change-date-character-string/m-p/443432#M110941</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-03-07T17:35:45Z</dc:date>
    </item>
  </channel>
</rss>

