<?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: Convert dates including partial dates to numeric format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729910#M227219</link>
    <description>&lt;P&gt;I would differ with the advice to keep the data as character variables.&amp;nbsp; Instead I suggest making 3 numeric variables: year, month, and day-of-month.&amp;nbsp; Sometimes the day-of-month or month variable will be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then create regular sas date values, imputing 1 for missing day-of-month, and 1 for missing month.&amp;nbsp; &amp;nbsp;This will support doing calculations and sorting using these (partly imputed, partly actual) date values.&amp;nbsp; And you can check for missing day-of-month or missing month to determine whether the date in hand is from complete or partial date components.&lt;/P&gt;</description>
    <pubDate>Mon, 29 Mar 2021 23:27:23 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-03-29T23:27:23Z</dc:date>
    <item>
      <title>Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729802#M227182</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Trying to convert the dates. Kindly help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a_;&lt;BR /&gt;input date $20.;&lt;BR /&gt;datalines ;&lt;/P&gt;&lt;P&gt;2020-10-20&lt;/P&gt;&lt;P&gt;2020-10&lt;/P&gt;&lt;P&gt;2020&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data b_;&lt;BR /&gt;format dtn yymmdd10.;&lt;BR /&gt;set a_;&lt;BR /&gt;if length(date) = 10 then do;&lt;BR /&gt;dtn=input(date,yymmdd10.);&lt;BR /&gt;end;&lt;BR /&gt;if length(date) = 7 then do;&lt;BR /&gt;dtn=input(compress(date,'-'),yymmn6.);&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;dtn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&lt;/P&gt;&lt;P&gt;2020-10-20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2020-10-20&lt;/P&gt;&lt;P&gt;2020-10-01&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2020-10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired output:&lt;/P&gt;&lt;P&gt;dtn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&lt;/P&gt;&lt;P&gt;2020-10-20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2020-10-20&lt;/P&gt;&lt;P&gt;2020-10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2020-10&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Due to format applied,01 is added.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 14:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729802#M227182</guid>
      <dc:creator>deepakg77717</dc:creator>
      <dc:date>2021-03-29T14:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729810#M227185</link>
      <description>&lt;P&gt;SAS does not recognize partial dates, and so these cannot be converted to numeric, except as you have seen where 2020-10 is internally represented as October 1, 2020, and shown as 2020-10-01. Similarly, 2020 is a partial date and would represented internally as January 1, 2020.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, given this is the case, what do you really want? If you really have to retain partial dates, just leave the strings as character.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 14:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729810#M227185</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-29T14:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729818#M227189</link>
      <description>&lt;P&gt;Thanks Paige Miller.. I got the reason..&lt;/P&gt;&lt;P&gt;Yes, I need the partial dates to be stored..&lt;/P&gt;&lt;P&gt;Could you please elaborate your suggestion. Since the column is defined as numeric, I am not able to assign character values. I get a Note: Invalid numeric data '2020-10' at ....&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 15:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729818#M227189</guid>
      <dc:creator>deepakg77717</dc:creator>
      <dc:date>2021-03-29T15:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729819#M227190</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262522"&gt;@deepakg77717&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please elaborate your suggestion.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do not convert to numeric, then the partial dates are preserved.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 15:20:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729819#M227190</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-29T15:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729820#M227191</link>
      <description>&lt;P&gt;SAS does not have a way to store partial dates, &lt;STRONG&gt;each date must have a day, month and year component&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An exception to this are datetimes in the ISO 8601 formats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=leforinforref&amp;amp;docsetTarget=p1a0qt18rxydrkn1b0rtdfh2t8zs.htm&amp;amp;locale=en#n07150tx0ht2whn18j1f963j1kmc"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=leforinforref&amp;amp;docsetTarget=p1a0qt18rxydrkn1b0rtdfh2t8zs.htm&amp;amp;locale=en#n07150tx0ht2whn18j1f963j1kmc&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you want to store your dates as shown you &lt;STRONG&gt;require&amp;nbsp;&lt;/STRONG&gt;a character variable or use a DATETIME variable with your hour minute seconds set to 0.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262522"&gt;@deepakg77717&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;Trying to convert the dates. Kindly help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a_;&lt;BR /&gt;input date $20.;&lt;BR /&gt;datalines ;&lt;/P&gt;
&lt;P&gt;2020-10-20&lt;/P&gt;
&lt;P&gt;2020-10&lt;/P&gt;
&lt;P&gt;2020&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data b_;&lt;BR /&gt;format dtn yymmdd10.;&lt;BR /&gt;set a_;&lt;BR /&gt;if length(date) = 10 then do;&lt;BR /&gt;dtn=input(date,yymmdd10.);&lt;BR /&gt;end;&lt;BR /&gt;if length(date) = 7 then do;&lt;BR /&gt;dtn=input(compress(date,'-'),yymmn6.);&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;output:&lt;/P&gt;
&lt;P&gt;dtn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date&lt;/P&gt;
&lt;P&gt;2020-10-20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2020-10-20&lt;/P&gt;
&lt;P&gt;2020-10-01&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2020-10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired output:&lt;/P&gt;
&lt;P&gt;dtn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date&lt;/P&gt;
&lt;P&gt;2020-10-20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;2020-10-20&lt;/P&gt;
&lt;P&gt;2020-10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2020-10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Due to format applied,01 is added.&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 15:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729820#M227191</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-29T15:27:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729837#M227194</link>
      <description>&lt;P&gt;Thank you for your reply ..Reeza..&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 16:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729837#M227194</guid>
      <dc:creator>deepakg77717</dc:creator>
      <dc:date>2021-03-29T16:47:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729838#M227195</link>
      <description>&lt;P&gt;Thank you again Paige Miller...&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 16:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729838#M227195</guid>
      <dc:creator>deepakg77717</dc:creator>
      <dc:date>2021-03-29T16:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729910#M227219</link>
      <description>&lt;P&gt;I would differ with the advice to keep the data as character variables.&amp;nbsp; Instead I suggest making 3 numeric variables: year, month, and day-of-month.&amp;nbsp; Sometimes the day-of-month or month variable will be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can then create regular sas date values, imputing 1 for missing day-of-month, and 1 for missing month.&amp;nbsp; &amp;nbsp;This will support doing calculations and sorting using these (partly imputed, partly actual) date values.&amp;nbsp; And you can check for missing day-of-month or missing month to determine whether the date in hand is from complete or partial date components.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Mar 2021 23:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/729910#M227219</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-29T23:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert dates including partial dates to numeric format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/730049#M227283</link>
      <description>&lt;P&gt;Yes, I agree with you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;that this is a better solution, but I asked the original poster specifically if the dates had to be maintained in their current form, where a missing day and month should be represented as 2021, and (s)he said yes. I suspect that after a short period of time trying to work with the character representation of full dates plus partial dates, (s)he will discover all the disadvantages that you point out, and then will make the decision to convert these to numeric.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Mar 2021 10:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-dates-including-partial-dates-to-numeric-format/m-p/730049#M227283</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-03-30T10:37:37Z</dc:date>
    </item>
  </channel>
</rss>

