Date: Mon, 25 Oct 1999 10:54:14 -0700
Reply-To: "Terjeson, Mark" <TERJEMW@DSHS.WA.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <TERJEMW@DSHS.WA.GOV>
Subject: Re: What is the correct date format?
Content-Type: text/plain
Hi Richard,
Two adjustments and you're off and running!
1) The x = '08jun1999'; needs to have the
trailing "d" on the string constant. Change
it to x='08jun1999'd;
2) The y=... assignment is yielding the string
' 14403'd containing spaces
inside the string. the location of the trim(left())
is not assisting soon enough. The Y variable
contains the spaces as it is passed to the PUT()
function and failing, and the the trim(left()) will
be performed on the "result" of the put() function.
You can leave the trim(left()) on the result of the
put(), but the Y also contains spaces, and a
trim(left()) will not work on Y because, even though
it contains spaces, it contains NO leading or trailing
spaces because the first character is an apostophe.
You can eliminate the spaces earlier as Y is built
from X.
y = "'"||trim(left(x))||"'"||'d';
However, while this does create Y='14403'd this
still does not work because the first argument to the
PUT() functions is expecting a numeric argument.
The '08jun1999'd is a CONSTANT that will be converted
by the compiler to be a numeric value 14403. So really,
the x='08jun1999'd; is exactly the same as writing
x=14403;
...then the PUT function is reality is put(14403,worddatx12.);
which will make the PUT function happy.
These will work fine:
x = '08jun1999'd;
newdate=trim(left(put( x,worddatx12.)));
newdate=trim(left(put( 14403,worddatx12.)));
newdate=trim(left(put( '08jun1999'd,worddatx12.)));
Additional note (converting string-to-numeric, numeric-to-string:
The input() function is passed a string variable and it returns
a numeric variable.
The put() function is passed a numeric variable and it returns
a string variable.
e.g.
numericVar = input( stringVar , informat);
stringVar = put( numericVar , format);
Hope This Helps,
Mark Terjeson
Washington State Department of Social and Health Services
Division of Research and Data Analysis (RDA)
(360) 902-0741
(360) 902-0705 fax
mailto:terjemw@dshs.wa.gov
> -----Original Message-----
> From: Richard James [SMTP:richard.e.james@CA.PWCGLOBAL.COM]
> Sent: Monday, October 25, 1999 9:16 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: What is the correct date format?
>
> This one has been bugging me for a short while.
>
>
> Consider this:
>
> data _null_;
> x = '08jun1999';
> y = "'"||x||"'"||'d';
> newdate=trim(left(put(y,worddatx12.)));
> put newdate=;
> RUN;
>
> Why will this not work?
|