Date: Wed, 11 Aug 2004 14:44:49 -0400
Reply-To: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject: Re: Implicit format type conversion in SAS?
When I learned SAS, my day care teacher told me that SAS allows use of a
numeric format in a PUT() function or command. In the special case of a
digit string (in some cases also including a decimal point), PUT formats the
string as it would a number displayed in the format specified.
That may explain the lack of an error message or warning. The compiler does
not distinguish a string in numeric syntax from any other string.
Still, I had expected the PUT to format a string as a number. I don't see
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mike
Sent: Wednesday, August 11, 2004 1:44 PM
Subject: Implicit format type conversion in SAS?
Has anyone ever tried something like the following?
LENGTH Var Newvar $ 24;
Var = 'This is very strange.';
Newvar = PUT(Var,8.);
PUT 'First 12 chars of Var are ' Var 12.;
PUT 'Value if Newvar is ' Newvar;
Much to my surprise, the above code works. (SAS 8.2, WinXP) When I was
much, much younger and I learned SAS on my momma's knee, she always taught
me that character formats started with $, that numeric formats didn't, and
that the format type always had to be consistent with the variable type.
I'm not sure whether this works by accident, whether it works because SAS is
being "smart" and "helpful", or whether there is some other simple
explanation I'm missing.