<?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: Partial date char to num in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698654#M213684</link>
    <description>&lt;P&gt;What is your desired result?&lt;/P&gt;</description>
    <pubDate>Fri, 13 Nov 2020 13:56:04 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-11-13T13:56:04Z</dc:date>
    <item>
      <title>Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698651#M213682</link>
      <description>&lt;P&gt;Hi Reader,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can I convert char to num below mentioned data, in final output i do not required partial date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data new;&lt;/P&gt;
&lt;P&gt;date = "2017-07-07" ; output ;&lt;BR /&gt;date = "2017"; output ;&lt;BR /&gt;date = "2007-11"; output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Priya&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-----------------------------------------------------&lt;/P&gt;
&lt;P&gt;==============================&lt;/P&gt;
&lt;P&gt;-----------------------------------------------------&lt;/P&gt;
&lt;P&gt;My final output is only 2017-07-07.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2nd and 3rd observation not required as it partial. Requirement is only for full date , which is in char and need to convert in num that is all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My approch is this -&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;proc sql ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;create table have as &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select case when length (date) = 10 then input(date,anydtdte20.) else . end as date format yymmdd10. &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from new ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you all for your replies.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2020 07:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698651#M213682</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-17T07:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698654#M213684</link>
      <description>&lt;P&gt;What is your desired result?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 13:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698654#M213684</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-13T13:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698658#M213685</link>
      <description>&lt;P&gt;Here, I simply assume that if month or day is missing then it is the first day/month..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=dt);
   set new;
   dt = catx('-', substr(date, 1, 4), 
             ifc(substr(date, 6, 7), substr(date, 6, 7), '01'), 
             ifc(substr(date, 9, 10), substr(date, 9, 10), '01'));
   date2 = input(dt, yymmdd10.);
   format date2 yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Nov 2020 14:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698658#M213685</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-13T14:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698668#M213687</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;conversion of partial date to numeric is not possible in SAS.&lt;/P&gt;
&lt;P&gt;You need to discuss the imputation strategy with a statistician and/or build a complete date first as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;did.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 14:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698668#M213687</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2020-11-13T14:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698671#M213688</link>
      <description>&lt;P&gt;The B8601DA in-format will impute DTC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;18   data _null_;
19      do dtc="2017-07-07","2017","2007-11";
20         date = input(dtc,b8601da.);
21         put (_all_)(=);
22         end;
23      format date date11.;
24      run;

dtc=2017-07-07 date=07-JUL-2017
dtc=2017 date=01-JAN-2017
dtc=2007-11 date=01-NOV-2007
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Nov 2020 14:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698671#M213688</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2020-11-13T14:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698675#M213689</link>
      <description>&lt;P&gt;Guru&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp; One comment is all I have. It's unfair for you to know everything leave alone me being jealous. That level of knowledge, speed and precision. Jeez!!&amp;nbsp; Sure you are aware and is nothing new that I would pay attention and take notes to your posts, albeit sometimes I worry that I can't keep up. In a way I am glad, you are not as frequent as you were in the past. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 15:05:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698675#M213689</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-13T15:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698676#M213690</link>
      <description>&lt;P&gt;The ANYDTDTE will handle two of the three strings with no NOTEs/WARNINGs/ERRORs, and a missing value for 2017...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results ; 
   set new ; 
   date_num = input(date,ANYDTDTE10.) ; 
   put date= date_num= ;
   format date_num date. ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It really does depend on what you want for the final results, e.g. for "2017", did you want&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;a number 2017&lt;/LI&gt;
&lt;LI&gt;a SAS Date value 20820 (01JAN2017)&lt;/LI&gt;
&lt;LI&gt;missing value&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;If you want just a number, try this...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results ; 
   set new ; 
   date_num = input(compress(date,,'kd'),10.) ; 
   put date= date_num= ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want a SAS Date Value, then you'll need to build some extra logic in to add at least a default month, and might be dependent on what other abbreviated values you have.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 14:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698676#M213690</guid>
      <dc:creator>MarkDawson</dc:creator>
      <dc:date>2020-11-13T14:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698679#M213692</link>
      <description>&lt;P&gt;Good to know about.&amp;nbsp; I always had to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = input(catt(date, '-01-01'), yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Nov 2020 14:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698679#M213692</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-11-13T14:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698689#M213698</link>
      <description>&lt;P&gt;You need to talk to your "customers" what they see as best for those partial dates, so that the later use won't skewer their statistics (too much).&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 15:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698689#M213698</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-13T15:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698929#M213791</link>
      <description>&lt;P&gt;Yes, those 1 Jan date frequency spikes are always highly suspect&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2020 02:26:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698929#M213791</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-11-15T02:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698936#M213794</link>
      <description>&lt;P&gt;With such partial dates, one might even consider to store separate year/month/day values, so the end user can decide how to handle missing months and/or days as is best for their current analysis.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2020 07:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/698936#M213794</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-15T07:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/700458#M214360</link>
      <description>&lt;P&gt;My final output is only 2017-07-07.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2nd and 3rd observation not required as it partial. Requirement is only for full date , which is in char and need to convert in num that is all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My approch is this -&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;proc sql ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;create table have as&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;select case when length (date) = 10 then input(date,anydtdte20.) else . end as date format yymmdd10.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from new ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you all for your reply.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 13:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/700458#M214360</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2020-11-20T13:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date char to num</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/700462#M214363</link>
      <description>&lt;P&gt;I suggest you use the YYMMDD10. informat after checking for a length of 10. I am wary of the ANY.... informats reading something in without a message when it is in fact nonsense disguising as a date.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Nov 2020 13:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Partial-date-char-to-num/m-p/700462#M214363</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-20T13:30:58Z</dc:date>
    </item>
  </channel>
</rss>

