Date: Thu, 4 Feb 2010 11:42:19 -0500
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: Parsing out Dates
In-Reply-To: <201002041636.o14BlNOM013195@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
Jim
You are quite correct. I should have rewritten it as '31dec1994'd
I have sent him a note offline asking for some more information on his data values. He has stated that it is numeric.
Nat
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Jim Groeneveld
Sent: Thursday, February 04, 2010 11:37 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Parsing out Dates
Hi Nathaniel,
The date form '12/31/1994'D is not valid, because it is ambiguous, maybe not
in this example, but it is in '01/02/1995'D. A log is:
1 DATA TestData;
2 Date1 = '12/31/1994'D;
_____________
77
ERROR: Invalid date/time/datetime constant '12/31/1994'D.
ERROR 77-185: Invalid number conversion on '12/31/1994'D.
3 Date2 = '01/02/1995'D;
_____________
77
ERROR: Invalid date/time/datetime constant '01/02/1995'D.
ERROR 77-185: Invalid number conversion on '01/02/1995'D.
4 FORMAT Date1 Date2 Date9.;
5 RUN;
So the text '12/31/1994' should be converted to a date using the explicit
MMDDYY10. informat in the INPUT function.
The original poster has to understand that the YEAR function applied on the
SAS date produces a numeric year that can be directly used to generate
frequencies. If he wants numbers from 1 he should subtract 1993 from the
Year value.
He may also build a format (that could be generated by macro code as well):
PROC FORMAT;
VALUE _Year
1994 = '01/01/1994 to 12/31/1994'
1995 = '01/01/1995 to 12/31/1995'
... and so on ... (that is why the macro building code)
;
RUN;
and add a FORMAT Year _Year; to a data or proc step using the Year variable.
Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
http://jim.groeneveld.eu.tf
On Thu, 4 Feb 2010 11:13:39 -0500, Nathaniel Wooding
<nathaniel.wooding@DOM.COM> wrote:
>Billy
>
>Sometimes the major part of the problem is figuring out how to couch the
question.
>
>If you print a few lines or (assuming that you are on windows) , open the
explorer window and click on your file, you will see this particular
variable. If the values are on the order of 12,000 and above (assuming that
they start in 1994) then you have a sas date value. Hence, you can refer to
a given value using SAS date literal format as in
>
>'01jan1994'd which stands for Jan 1, 1994, or 12,419
>
>Hence, your code should be
>
>
>if ratedpilotsnew2 le '12/31/1994'D then date = 0; else date = 1; *
letter d added to date value;
>
>Try using the single line statement that I gave you. If it works, it really
simplifies the coding if you are looking at many years.
>
>-----Original Message-----
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Billy
Thompson
>Sent: Thursday, February 04, 2010 11:06 AM
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Re: Parsing out Dates
>
>Nat,
>
>Proc Contents identifies the date variable as numeric. The actual code I
>originally tried was
>
>if ratedpilotsnew2 le '12/31/1994' then date = 0; else date = 1;
>
>this was just an attempt to see if it worked and I could get two
>groupings. If it did I would then parse out each year through 2009.
>
>BTW, thanks everyone for helping inspite of my not communicating exactly
>what it is I need to do. Thanks for your patience.
>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.