| Date: | Sat, 6 Sep 2008 13:03:28 -0700 |
| Reply-To: | Jack Hamilton <jfh@STANFORDALUMNI.ORG> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Jack Hamilton <jfh@STANFORDALUMNI.ORG> |
| Subject: | Re: convert date format |
|
| In-Reply-To: | <242618.87505.qm@web34202.mail.mud.yahoo.com> |
| Content-Type: | text/plain; charset=US-ASCII; format=flowed; delsp=yes |
You need to show us your error messages, and give us more details
about the data.
It sounds like some of your variables are numeric and others are
character; that might be the problem. The format assigned to a SAS
date value stored in a numeric variable does not affect how that
variable is used in calculations.
In the code below, the line "dc{4} date_base dateyear1 dateyear2
dateyear3;" is after the run statement, and that will cause an error.
--
Jack Hamilton
jfh@alumni.stanford.org
videtis illam spirare libertatis auram
On Sep 6, 2008, at 12:14 pm, hua gang wrote:
> Thanks for reply, Dan.
>
> I used the following to compute the difference between yearsly
> dates, only my first date variable, "date_base" has different format
> like, 03JUN08. Because of it, the computation didn't work. Once I
> got ride of date_base," and datedif0 it worked perfectly. So, this
> is the reason for me to try to convert "date_base", but I can't find
> a way to do it right away.
>
> Thanks again for your help.
>
> Hua
>
> array
> arraydd{4} datediff0 datediff1 datediff2 datediff3;seth4;do
> last_date=
> j=i;
> dd{i}=
> j=j-i=2to4;.;.;dountil((last_date ne .) or (dc{i} = .));1;ifdc{j}
> ne .thenlast_date=j;elseifj=1thenleave;end;/* only need to do a diff
> here since SAS dates count days from a set point */
> ifnmiss(last_date,dc{i})=0thendd{i}=dc{i}-dc{last_date};end;dropi j;
> *last_date;run;
> dc{4} date_base dateyear1 dateyear2 dateyear3;
>
>
> ----- Original Message ----
> From: Daniel Nordlund <djnordlund@VERIZON.NET>
> To: SAS-L@LISTSERV.UGA.EDU
> Sent: Saturday, September 6, 2008 1:56:51 PM
> Subject: Re: convert date format
>
>> -----Original Message-----
>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf
>> Of hua
>> gang
>> Sent: Saturday, September 06, 2008 10:48 AM
>> To: SAS-L@LISTSERV.UGA.EDU
>> Subject: Re: convert date format
>>
>> Thanks for comment. Not for display purpose, I wanted to convert
>> all dates in the
>> same format for computational purpose.
>> In my current data set, some dates are in one format, and others
>> are in different
>> format.
>>
>> Hua
>>
>
> But that was Jack's point. If you are using SAS dates (and if you
> aren't, you should), it doesn't matter if they are formatted
> differently, no conversion is necessary. The only exception would
> be if you both SAS dates and SAS datetimes. In that case you will
> need to convert the datetimes to dates (or dates to datetimes), and
> for that you would use the datepart() function (or dhms() function).
>
> Hope this is helpful,
>
> Dan
>
> Daniel Nordlund
> Bothell, WA USA
|