Date: Wed, 5 May 2004 12:49:29 -0400
Reply-To: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Howard Schreier <Howard_Schreier@ITA.DOC.GOV>
Subject: Re: Propagating Date Problem!
I am going to start from scratch.
Here is a shortened version of the test dataset:
data before;
input ddmmm $;
cards;
22-Jan
21-Feb
13-Nov
12-Dec
11-Jan
8-Jul
2-Dec
31-Dec
02-Mar
;
We have to assume that there are no "invisible" year rollovers; that is, no
jumps of a year or more from observation to the next.
My solution:
data after;
set before;
retain year 1970;
sasdate = input(compress(ddmmm||'1919',' -'),date9.);
if sasdate < lag(sasdate) then year ++ 1;
sasdate = mdy(month(sasdate),day(sasdate),year);
format sasdate date9.;
run;
The first assignment statement constructs a SAS date in an arbitrary year
(I chose 1919). The IF statement tests for year rollover. The second
assignment statement moves the date into the correct year.
On Tue, 4 May 2004 16:30:50 -0400, Ross, Michael D
<michael.ross@ASTRAZENECA.COM> wrote:
>Hello,
> I have the following dates from 1970 - 2020 (an excerpt below). I need Sas
>dates - but I'm having trouble adding the year. Here's my code: Any
>suggestions?
>
>Data month2;
>retain year 1970;
>set month2;
>by month;
>if first.month eq 'JAN' then year='1970';
> else year=year+1;
>run;
>
>22-Jan
>21-Feb
>23-Mar
>21-Apr
>21-May
>19-Jun
>18-Jul
>17-Aug
>15-Sep
>14-Oct
>13-Nov
>12-Dec
>11-Jan
>10-Feb
>12-Mar
>10-Apr
>10-May
>9-Jun
>8-Jul
>6-Aug
>5-Sep
>4-Oct
>2-Nov
>2-Dec
>31-Dec