| Date: | Mon, 30 Mar 1998 18:59:39 GMT |
| Reply-To: | Jay Weedon <jweedon@EARTHLINK.NET> |
| Sender: | "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU> |
| From: | Jay Weedon <jweedon@EARTHLINK.NET> |
| Organization: | http://extra.newsguy.com |
| Subject: | Re: date questions |
| Content-Type: | text/plain; charset=us-ascii |
On Mon, 30 Mar 1998 10:48:35 -0500, "Alderton, David" <dla5@CDC.GOV>
wrote:
>I have several different types of 'dates'. One variable is INTDT which
>is a traditional SAS date (number). For several others, what I have is
>the month and year, not the day, and these are currently stored as short
>numbers (numeric length 4): 796 means July 1996, 1295 means December
>1995, etc. For some of these values, a missing month is coded as 77 or
>99 (similarly for the year).
>
>What I would like to accomplish it to count the number of MONTHS between
>the SAS date in INTDT and the implied date in the short numeric
>variables.
>
>Can someone share their thoughts on the best way. I'm working through
>it but have little expertise with date problems.
Well the concept of "number of months between" isn't completely
precise in itself (and if you use 77 or 99 as missing values for years
you could get into some terrible trouble!) but you could try something
along these lines:
1. Convert the short date to a string "0796" or "1295".
2. Check for missing values, and abort if found.
3. Stick a "15" in front to get "150796" or "151295".
4. Read this string as a SAS date in ddmmyy6. format.
5. Subtract this date from the other numeric date.
6. Divide by 30.44 to get the approx. time (in months) between the
middle of the one month and the exact date of the other month.
e.g., if your short date is variable DATE1:
data new;
set old;
string=put(date1,z4.);
if substr(string,1,2)^in ('77','99') and
substr(string,3,2)^in ('77','99') then do;
date2=input('15'||string,ddmmyy6.);
diff=(date2-intdt)/30.44;
end;
run;
Depending on your exact needs, you may want to look at the INTCK()
function, or maybe the FLOOR() or CEIL() function instead.
Jay Weedon.
|