<?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 conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575012#M162556</link>
    <description>&lt;P&gt;So is the first delimited value supposed to be the day of the month and the second value the month number?&lt;/P&gt;
&lt;P&gt;If so then once you have replaced the text with digits you can use the DDMMYY informat to convert it to a real date&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jul 2019 16:58:13 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-07-19T16:58:13Z</dc:date>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575008#M162555</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Similar to this old thread:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Partial-date-conversion/td-p/197941" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Partial-date-conversion/td-p/197941&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've a date like 21:unk:1997&lt;BR /&gt;01:03:1998&lt;BR /&gt;10:09:1994&lt;BR /&gt;Unk:09:1999&lt;BR /&gt;Unk:unk:2000&lt;BR /&gt;I want replace day 'unk'=01 if month is in 01-06&lt;BR /&gt;Else unk=30&lt;BR /&gt;Month 'unk'='01' if day is in 01-15&lt;BR /&gt;Else month='12';&lt;BR /&gt;Anybody knows the process please let me know!!??&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 16:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575008#M162555</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-19T16:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575012#M162556</link>
      <description>&lt;P&gt;So is the first delimited value supposed to be the day of the month and the second value the month number?&lt;/P&gt;
&lt;P&gt;If so then once you have replaced the text with digits you can use the DDMMYY informat to convert it to a real date&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 16:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575012#M162556</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T16:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575014#M162557</link>
      <description>&lt;P&gt;You didn't give a rule for missing day and missing month.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input string $20.;
cards;
21:unk:1997
01:03:1998
10:09:1994
Unk:09:1999
Unk:unk:2000
;

data want ;
  set have;
  day=input(scan(string,1,':'),??4.);
  month=input(scan(string,2,':'),??4.);
  year=input(scan(string,3,':'),??4.);
  if missing(day) then do;
    if month in (1:6) then day=1;
    else if month in (7:12) then day=30;
  end;
  if missing(month) then do;
    if day in (1:15) then month=1;
    else if day in (16:31) then month=12;
  end;
  if n(day,month,year)=3 then date=mdy(month,day,year);
  format date yymmdd10.;
run;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs       string       day    month    year          date

 1     21:unk:1997      21      12     1997    1997-12-21
 2     01:03:1998        1       3     1998    1998-03-01
 3     10:09:1994       10       9     1994    1994-09-10
 4     Unk:09:1999      30       9     1999    1999-09-30
 5     Unk:unk:2000      .       .     2000             .&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2019 17:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575014#M162557</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T17:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575015#M162558</link>
      <description>Tnqq so much..and I've a doubt.so why you were used n(day,month,year)=3</description>
      <pubDate>Fri, 19 Jul 2019 17:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575015#M162558</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-19T17:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575016#M162559</link>
      <description>And If we have both day and month =unk then the values are 01 and 01</description>
      <pubDate>Fri, 19 Jul 2019 17:13:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575016#M162559</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-19T17:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575033#M162575</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;And If we have both day and month =unk then the values are 01 and 01&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should be able to make the needed changes to test for that condition and assign those values.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 18:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575033#M162575</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T18:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575034#M162576</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282134"&gt;@sasuser123123&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Tnqq so much..and I've a doubt.so why you were used n(day,month,year)=3&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To avoid NOTE in log about MDY() function generating missing values because of missing inputs.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2019 18:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575034#M162576</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-19T18:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575093#M162605</link>
      <description>By doing that above program..I got a note on log window that shows..&lt;BR /&gt;Note:: Invalid Numeric data,month='unk'&lt;BR /&gt;Note:: Invalid Numeric data ,day='unk'</description>
      <pubDate>Sat, 20 Jul 2019 05:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575093#M162605</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-20T05:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575094#M162606</link>
      <description>I've used if day='unk' then day=1</description>
      <pubDate>Sat, 20 Jul 2019 05:42:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575094#M162606</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-20T05:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575104#M162615</link>
      <description>Is DAY a numeric variable or a character variable in your program?  If it is numeric then it cannot have a value like 'unk'.  If it is character then you shouldn't try to assign a numeric value to it.&lt;BR /&gt;Perhaps you meant:&lt;BR /&gt;if missing(day) then day=1;&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Jul 2019 06:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575104#M162615</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-20T06:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575117#M162618</link>
      <description>I've dates like01:unk:1997&lt;BR /&gt;18:unk:1999&lt;BR /&gt;Unk:09:2000&lt;BR /&gt;Unk:unk:2010;&lt;BR /&gt;So I'm trying to convert these partial dates to normal by using these conditions...&lt;BR /&gt;If date is missing so take 01 when month between jan-jul otherwise take 30&lt;BR /&gt;If month is missing take 01 when date between 1 t0 15 otherwise 12..&lt;BR /&gt;So I run below program it shows some notes like invalid numeric data month='unk' ......&lt;BR /&gt;So please modify below program&lt;BR /&gt;Data hx;&lt;BR /&gt;Set for;&lt;BR /&gt;Day=scan(start date,1,':');&lt;BR /&gt;Month=scan(start date,2,':');&lt;BR /&gt;Year=scan(start date,3,':');&lt;BR /&gt;If day='unk' then do;&lt;BR /&gt;If month in(01:06) then day='01';&lt;BR /&gt;Else if month in (07:12) then day='30';&lt;BR /&gt;End;&lt;BR /&gt;If month='unk' then do;&lt;BR /&gt;If day in(01:06) then month='01';&lt;BR /&gt;Else if day in (07:12) then month='12';&lt;BR /&gt;End;&lt;BR /&gt;If month='unk' then month='01';&lt;BR /&gt;If day='unk' then day='01';&lt;BR /&gt;Date=mdy(month,day,year);&lt;BR /&gt;Run;&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Jul 2019 08:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575117#M162618</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-20T08:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575121#M162620</link>
      <description>Can get Your Contact..</description>
      <pubDate>Sat, 20 Jul 2019 09:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575121#M162620</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-20T09:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575125#M162621</link>
      <description>I've dates like01:unk:1997&lt;BR /&gt;18:unk:1999&lt;BR /&gt;Unk:09:2000&lt;BR /&gt;Unk:unk:2010;&lt;BR /&gt;So I'm trying to convert these partial dates to normal by using these conditions...&lt;BR /&gt;If date is missing so take 01 when month between jan-jul otherwise take 30&lt;BR /&gt;If month is missing take 01 when date between 1 t0 15 otherwise 12..&lt;BR /&gt;So I run below program it shows some notes like invalid numeric data month='unk' ......&lt;BR /&gt;So please modify below program&lt;BR /&gt;Data hx;&lt;BR /&gt;Set for;&lt;BR /&gt;Day=scan(start date,1,':');&lt;BR /&gt;Month=scan(start date,2,':');&lt;BR /&gt;Year=scan(start date,3,':');&lt;BR /&gt;If day='unk' then do;&lt;BR /&gt;If month in(01:06) then day='01';&lt;BR /&gt;Else if month in (07:12) then day='30';&lt;BR /&gt;End;&lt;BR /&gt;If month='unk' then do;&lt;BR /&gt;If day in(01:06) then month='01';&lt;BR /&gt;Else if day in (07:12) then month='12';&lt;BR /&gt;End;&lt;BR /&gt;If month='unk' then month='01';&lt;BR /&gt;If day='unk' then day='01';&lt;BR /&gt;Date=mdy(month,day,year);&lt;BR /&gt;Run</description>
      <pubDate>Sat, 20 Jul 2019 10:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575125#M162621</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-20T10:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575145#M162626</link>
      <description>&lt;P&gt;If you do not define your variable explicitly with a LENGTH or ATTRIB statement then SAS will define them based on how you first use them in the code.&amp;nbsp; So DAY is defined as CHARACTER by this statement because it is assigning it the result of a character function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;day=scan(start date,1,':');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you define DAY as a character variable then if you compare it to numeric values, as you are doing in this test:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If day in(01:06)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then SAS will at run time try to convert the characters in DAY into a number.&amp;nbsp; (Note: The syntax N:M is short hand for all of the integers between N and M, inclusive.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;That is why it is giving you the warning about unk being an invalid number.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Go back the version I posted where DAY, MONTH and YEAR are created as numeric variables.&amp;nbsp; And modify your tests for UNK to test for missing values instead.&amp;nbsp; Such as:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if day=. then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(day) then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jul 2019 15:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575145#M162626</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-20T15:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Partial date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575146#M162627</link>
      <description>Thank you much...For your support&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Jul 2019 15:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Re-Partial-date-conversion/m-p/575146#M162627</guid>
      <dc:creator>sasuser123123</dc:creator>
      <dc:date>2019-07-20T15:35:13Z</dc:date>
    </item>
  </channel>
</rss>

