Date: Thu, 1 Apr 2010 22:01:55 -0400
Reply-To: Nathaniel Wooding <nathaniel.wooding@DOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nathaniel Wooding <nathaniel.wooding@DOM.COM>
Subject: Re: The problem with sorting MONYY7. data
Content-Type: text/plain; charset="us-ascii"
You have received several replies pointing out that what you have are character strings and SAS has no idea that you see them as dates. Moreover, the statement that the type is MONYY7. is incorrect. As a couple other have implied, SAS stores dates as the number of days (or if a date time value, the number of seconds) since Jan 1, 1960 which is day 0. Try running the code
date = '01jan1960'd;* this is referred to as a date literal;
format date monyy7.;
rawdate = date;
Note that I apply a format -- MONYY7. -- to the variable date and it prints with that format. I do not use a format with RAWDATE and it appears as the actual numeric value. Please keep in mind that SAS still is storing date a 0 and will display the date in other formats should you choose to use one of these. If you were to use the SAS Explorer to look at the set "DATE" and clicked on either of the two date columns and then on properties, you could select other date formats and see the column displayed with that particular format. However, the underlying value will not be changed.
If you have a series of dates such as you showed, you may use the SAS Input function with the informat MONYY7. To read the original date and put it in a new variable that is stored as a SAS date. Try the code
Cdate = 'Jan2002';
SASDate = input( cDate , monyy7.);
Date = SASdate;
Format SASDATE DDmMyy10.;
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of QiJun Fung
Sent: Thursday, April 01, 2010 4:50 PM
Subject: The problem with sorting MONYY7. data
I have a column "date" with type MONYY7.
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:
How can I sort it by time order?
Thanks very much.
CONFIDENTIALITY NOTICE: This electronic message contains
information which may be legally confidential and or privileged and
does not in any case represent a firm ENERGY COMMODITY bid or offer
relating thereto which binds the sender without an additional
express written confirmation to that effect. The information is
intended solely for the individual or entity named above and access
by anyone else is unauthorized. If you are not the intended
recipient, any disclosure, copying, distribution, or use of the
contents of this information is prohibited and may be unlawful. If
you have received this electronic transmission in error, please
reply immediately to the sender that you have received the message
in error, and delete it. Thank you.