How to transform datetime19. to yymm7.

  • Follow


Hi all,

I am very sorry to bother you again. I encounter a problem recently. I
just tried what I know, but still can not figure it out.

I  have a variable called date in my date set with format datetime19.
like  "17NOV2008:00:00:00". Now I only want month and year format
yymm.  like"2008M11". I use the following code:

data one;
format date2 yymm.;
date2=put(date, yymm.);
run;

However, it did not work since in date2 column it shows
'***********'.  And another thing I was very confused is what is the
difference between format and informat. Do I need to use informat
statement to change the variable's format?

Can anyone give me some hint? Thanks very much for your time.

Have a good weekend!
0
Reply coolcong (8) 4/9/2010 7:52:29 PM

I think it's input function not put function. Try input function.
On Apr 9, 2:52=A0pm, QiJun Fung <coolc...@gmail.com> wrote:
> Hi all,
>
> I am very sorry to bother you again. I encounter a problem recently. I
> just tried what I know, but still can not figure it out.
>
> I =A0have a variable called date in my date set with format datetime19.
> like =A0"17NOV2008:00:00:00". Now I only want month and year format
> yymm. =A0like"2008M11". I use the following code:
>
> data one;
> format date2 yymm.;
> date2=3Dput(date, yymm.);
> run;
>
> However, it did not work since in date2 column it shows
> '***********'. =A0And another thing I was very confused is what is the
> difference between format and informat. Do I need to use informat
> statement to change the variable's format?
>
> Can anyone give me some hint? Thanks very much for your time.
>
> Have a good weekend!

0
Reply Mo 4/9/2010 8:26:41 PM


What you have makes date2 a character variable.  yymm is a numeric
format which should only be used with numeric variables.

Since the data is in a datetime variable and you want to process only
the date part, try 
    date2 = datepart(date);

On Fri, 9 Apr 2010 12:52:29 -0700 (PDT), QiJun Fung
<coolcong@gmail.com> wrote:

>Hi all,
>
>I am very sorry to bother you again. I encounter a problem recently. I
>just tried what I know, but still can not figure it out.
>
>I  have a variable called date in my date set with format datetime19.
>like  "17NOV2008:00:00:00". Now I only want month and year format
>yymm.  like"2008M11". I use the following code:
>
>data one;
>format date2 yymm.;
>date2=put(date, yymm.);
>run;
>
>However, it did not work since in date2 column it shows
>'***********'.  And another thing I was very confused is what is the
>difference between format and informat. Do I need to use informat
>statement to change the variable's format?
>
>Can anyone give me some hint? Thanks very much for your time.
>
>Have a good weekend!

-- 
Remove del for email
0
Reply Barry 4/10/2010 4:43:23 AM

2 Replies
291 Views

(page loaded in 0.082 seconds)

Similiar Articles:





7/23/2012 6:22:53 PM


Reply: