Date: Sat, 22 Jun 1996 15:45:17 EDT
Reply-To: John Whittington <100517.3677@COMPUSERVE.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: John Whittington <100517.3677@COMPUSERVE.COM>
Subject: Re: reading character variable as numeric
On Sat, 22 Jun 1996, Ramu Thiagarajan <ramut@NWU.EDU> wrote:
> I have a data set wherein one of the variables has a character
> suffix which is redundant. Example: 0 is coded as 0_ (i.e.,
> there is an underscore attaced to the number that is redundant).
> I am not able to use column input because the numbers are not
> in the same column throughout the data set. So, I am using
> line input.
> What is the best way to read this as a numeric variable
> wherein I cannot use a column input format
> Or is it better to convert into numeric variable reading
> it as a character variable.
Ramu, I'm not sure that you have any options here. If you cannot use column
input, then I think you will have to read the variable in as a character
variable, get rid of the non-numeric character(s), and then convert the
'cleaned' character variable to a numeric one.
If you know that there is *always* going to be a single non-numeric character
suffix, then the 'cleaning' process might be as simple as:
charvar = substr (charvar, 1, length(charvar)-1) ;
Otherwise, you could use the compress() function to extract only the numeric
characters, as recently described on SAS-L by Karsten Self.
Either way, the character-to-numeric conversion can then be done using the
Dr John Whittington
Mediscience Services Ltd.,
Twyford Manor, Twyford, Buckingham, MK18 4EL UK
voice: +44 (0) 1296 730225 fax: +44 (0) 1296 738893