<?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: SAS Partial Dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/747004#M234423</link>
    <description>Hi Jimbarbour,&lt;BR /&gt;i was able to resolve that by applying the following code below for the AESTDTC. However, since the AEENDTC is U, i guess its unknown and it has to be missing.&lt;BR /&gt;&lt;BR /&gt;*Y/M/D for partial date;&lt;BR /&gt;   yearst  = scan(aestdtc,3,'-');&lt;BR /&gt;   monthst = scan(aestdtc,2,'-');&lt;BR /&gt;   dayst   = scan(aestdtc,1,'-');&lt;BR /&gt;   if length(yearst) =3 then yearst=compress(yearst||'0');&lt;BR /&gt;   AESTDT=mdy(monthst,dayst,yearst);&lt;BR /&gt;&lt;BR /&gt;Regards</description>
    <pubDate>Thu, 10 Jun 2021 12:46:48 GMT</pubDate>
    <dc:creator>chimukah</dc:creator>
    <dc:date>2021-06-10T12:46:48Z</dc:date>
    <item>
      <title>SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746833#M234328</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please i have a partial date problem for both starting of and ending of adverse event.&lt;/P&gt;
&lt;P&gt;the aestdtc = 18-11-202&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; aeendtc= U-U-2020&lt;/P&gt;
&lt;P&gt;How do i impute this partial dates knowing fully well that other dates in the column have length as&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;aestdtc = 7-5-2020 where 7 corresponds to Day and 5 corresponds to Month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warm regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 17:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746833#M234328</guid>
      <dc:creator>chimukah</dc:creator>
      <dc:date>2021-06-09T17:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746920#M234384</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/225077"&gt;@chimukah&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please i have a partial date problem for both starting of and ending of adverse event.&lt;/P&gt;
&lt;P&gt;the aestdtc = 18-11-202&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; aeendtc= U-U-2020&lt;/P&gt;
&lt;P&gt;How do i impute this partial dates knowing fully well that other dates in the column have length as&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;aestdtc = 7-5-2020 where 7 corresponds to Day and 5 corresponds to Month.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Well, this is a bit difficult.&amp;nbsp; You may not be able to correctly determine some dates given partial dates like these.&amp;nbsp; However, there are some things that you can do:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Parse the data.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;First, you would want to break the date into its Day, Month, and Year components using the SCAN function with '-' as your delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Correct the data.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;Second, you would create correction rules such as:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Start dates that are invalid will default to January 1st of the year indicated by the date.&lt;/LI&gt;
&lt;LI&gt;End dates that are invalid will default to December 31st of the year indicated in the date.&lt;/LI&gt;
&lt;LI&gt;Years equal to 202 will be set to 2020.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;You could make more sophisticated rules, like setting a range on what years are valid or imputing the start year from the end year if the end year is valid, but the above are some ideas to start with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Check the data.&amp;nbsp;&amp;nbsp;&lt;/STRONG&gt;Third, you would want to identify illogical or invalid conditions that remain after your parsing and correcting.&amp;nbsp; The End should not be before the Start, for example.&amp;nbsp; Perhaps you would want to delete records with illogical conditions from the final data or at least set the illogical values to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is a sample program that encodes these steps (parse, correct, check).&amp;nbsp; The program probably won't do everything you need, but you can use it as a starting point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA	Corrected_Dates	(KEEP=Final_aestdtc Final_aeendtc);
	FORMAT	Final_aestdtc	DATE9.;
	FORMAT	Final_aeendtc	DATE9.;

	INFILE	Datalines		DSD	DLM='09'X	MISSOVER;

	INPUT
		aestdtc	$	
		aeendtc	$
		;

	Work_Date				=	aestdtc;
	Type					=	'START';
	LINK	Parse_Date;
	Final_aestdtc			=	SAS_Date;

	Work_Date				=	aeendtc;
	Type					=	'END';
	LINK	Parse_Date;
	Final_aeendtc			=	SAS_Date;

	IF	MISSING(Final_aestdtc)					THEN
		DO;
			PUTLOG	"WARNING:  Invalid start date on record "  _N_=  COMMA17.;
		END;

	IF	MISSING(Final_aeendtc)					THEN
		DO;
			PUTLOG	"WARNING:  Invalid end date on record "  _N_=  COMMA17.;
		END;

	IF	Final_aeendtc		&amp;lt;	Final_aestdtc	THEN
		DO;
			PUTLOG	"WARNING:  End before start on record "  _N_=  COMMA17.;
			CALL	MISSING(Final_aestdtc, Final_aeendtc);
		END;

	******;
	RETURN;
	******;

	**********;
	Parse_Date:
	**********;
		Day					=	SCAN(Work_Date, 1, '-');
		Month				=	SCAN(Work_Date, 2, '-');
		Year				=	SCAN(Work_Date, 3, '-');

		IF	Type			=	'START'			THEN
			DO;
				IF	NOTDIGIT(STRIP(Day))		THEN
					Day		=	'1';
				IF	NOTDIGIT(STRIP(Month))		THEN
					MONTH	=	'1';
			END;

		IF	Type			=	'END'			THEN
			DO;
				IF	NOTDIGIT(STRIP(Day))		THEN
					Day		=	'31';

				IF	NOTDIGIT(STRIP(Month))		THEN
					MONTH	=	'12';
			END;

		IF	Year			=	'202'			THEN
			Year			=	'2020';

		SAS_Date			=	MDY(INPUT(STRIP(Month), 2.), INPUT(STRIP(Day), 2.), INPUT(STRIP(Year), 4.));
	******;
	RETURN;
	******;

DATALINES;
18-11-202	U-U-2020
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Jun 2021 00:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746920#M234384</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-10T00:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746944#M234396</link>
      <description>Thank you Jimbarbour for your kind explanation and assistance in resolving this puzzle. I will implement same and see the outcome. &lt;BR /&gt;Best regards,&lt;BR /&gt;Chimuka</description>
      <pubDate>Thu, 10 Jun 2021 07:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746944#M234396</guid>
      <dc:creator>chimukah</dc:creator>
      <dc:date>2021-06-10T07:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746949#M234397</link>
      <description>&lt;P&gt;First of all you need to define the rules how to interpret incomplete dates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you know/can you say what dates your incomplete dates actually stand for (for all cases).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF you can define exhaustive rules then you can write the code for it. What&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;posted is code to implement such rules - but are the rules used really sufficient for your actual data?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i.e. should&amp;nbsp;&lt;SPAN&gt;aestdtc = 18-01-202 become 18Nov2020 or 18Nov2021? What other information do you have to define a rule which would provide the correct answer? Can there be a rule at all? Could you always know by looking at the data?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;...and of course ideally: Instead of trying to fix bad data go back to the the source/data provider and request data of better quality.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 07:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746949#M234397</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-06-10T07:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746956#M234399</link>
      <description>Thank you Patrick.&lt;BR /&gt;However when the database is locked and the source data cannot be changed then only data programming can correct such anomalies. In this case it should be 18NOV2020. &lt;BR /&gt;Thank you.</description>
      <pubDate>Thu, 10 Jun 2021 08:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746956#M234399</guid>
      <dc:creator>chimukah</dc:creator>
      <dc:date>2021-06-10T08:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746959#M234402</link>
      <description>&lt;P&gt;Then you need to list and analyze all the string you can't convert to a SAS date value and define the rules for conversion. I'd consider insufficient rules converting incomplete strings to the wrong SAS date values as even worse than having to deal with missing dates. Creating "inappropriate" dates will mask DQ issues and can lead to wrong conclusions.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 09:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/746959#M234402</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-06-10T09:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/747004#M234423</link>
      <description>Hi Jimbarbour,&lt;BR /&gt;i was able to resolve that by applying the following code below for the AESTDTC. However, since the AEENDTC is U, i guess its unknown and it has to be missing.&lt;BR /&gt;&lt;BR /&gt;*Y/M/D for partial date;&lt;BR /&gt;   yearst  = scan(aestdtc,3,'-');&lt;BR /&gt;   monthst = scan(aestdtc,2,'-');&lt;BR /&gt;   dayst   = scan(aestdtc,1,'-');&lt;BR /&gt;   if length(yearst) =3 then yearst=compress(yearst||'0');&lt;BR /&gt;   AESTDT=mdy(monthst,dayst,yearst);&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Thu, 10 Jun 2021 12:46:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/747004#M234423</guid>
      <dc:creator>chimukah</dc:creator>
      <dc:date>2021-06-10T12:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Partial Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/747051#M234440</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/225077"&gt;@chimukah&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;since the AEENDTC is U, i guess its unknown and it has to be missing.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, that's probably best.&amp;nbsp; As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;points out, it's typically better to set a value to missing than to give a value that will produce invalid or misleading results.&amp;nbsp; If you're not sure, the safest course is to set to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The little program I showed you can be used as a sort of pattern or template for the parse-clean-check process, but &lt;EM&gt;you&lt;/EM&gt; must determine what cleaning rules are appropriate for your situation and your data.&amp;nbsp; My program is meant to illustrate a technique but by no means should you accept my sample rules unless they really fit your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jun 2021 15:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Partial-Dates/m-p/747051#M234440</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-06-10T15:04:42Z</dc:date>
    </item>
  </channel>
</rss>

