From: QiJun Fung on
Hi all,

I have a column "date" with type MONYY7.
eg. Jun2004
Apr2001
Apr2004
.
.

When I sort the data by "date", the order is by alphabetical order of
the initial not by its time order.Then the result is like:
Apr2001
Apr2004
Jun2004

How can I sort it by time order?

Thanks very much.

Cong
From: MichelleZ on
On Apr 1, 3:50 pm, QiJun Fung <coolc...(a)gmail.com> wrote:
> Hi all,
>
> I have a column "date" with type MONYY7.
> eg.  Jun2004
>        Apr2001
>        Apr2004
>           .
>           .
>
> When I sort the data by "date", the order is by alphabetical order of
> the initial not by its time order.Then the result is like:
>      Apr2001
>      Apr2004
>      Jun2004
>
> How can I sort it by time order?
>
> Thanks very much.
>
> Cong

Change the variables so they are yyyymm as in
200104
200404
200406

and then sort.
From: Chris Jones on
On 1 Apr, 22:24, MichelleZ <michelle_zunnur...(a)hotmail.com> wrote:
> On Apr 1, 3:50 pm, QiJun Fung <coolc...(a)gmail.com> wrote:
>
>
>
>
>
> > Hi all,
>
> > I have a column "date" with type MONYY7.
> > eg.  Jun2004
> >        Apr2001
> >        Apr2004
> >           .
> >           .
>
> > When I sort the data by "date", the order is by alphabetical order of
> > the initial not by its time order.Then the result is like:
> >      Apr2001
> >      Apr2004
> >      Jun2004
>
> > How can I sort it by time order?
>
> > Thanks very much.
>
> > Cong
>
> Change the variables so they are yyyymm as in
> 200104
> 200404
> 200406
>
> and then sort.

You should keep the data stored as a SAS date, and apply monyy7. as a
format - it'll always sort correctly then.
From: Lou on

"QiJun Fung" <coolcong(a)gmail.com> wrote in message
news:2a884e16-5642-487a-aff9-d7ce5fc4866f(a)x3g2000yqd.googlegroups.com...
> Hi all,
>
> I have a column "date" with type MONYY7.
> eg. Jun2004
> Apr2001
> Apr2004
> .
> .

No you don't. SAS has only two data types - character and numeric. You
have either a character variable with values like those you cite, or you
have a numeric variable associated with format MONYY7.

If it's a character variable, a sort will put the values in alphabetical
order. If it's numeric with an associated format, the underlying values are
the number of days since 01-Jan-1960, and a sort will put them in numeric
order, which for dates means chronological order.

>
> When I sort the data by "date", the order is by alphabetical order of
> the initial not by its time order.Then the result is like:
> Apr2001
> Apr2004
> Jun2004
>
> How can I sort it by time order?

Chronologically, Apr2001 is before Apr2004, which in turn is before Jun2004.
For the values in your example, chronological and alphabetical order are the
same. And we can't tell if you're sorting character or numeric values from
your example.

> Thanks very much.
>
> Cong