Date: Sat, 25 Oct 1997 14:02:02 -0700
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: JP Snow <yeti@SLIP.NET>
Organization: Slip.Net (http://www.slip.net)
Subject: Re: Changing a SAS char. variable to a numeric variable keeping
the varname ??
Content-Type: text/plain; charset=us-ascii
To convert character to numeric:
where informat is appropriate for your data (e.g. 3. for integers
less than 1000, etc.)
This is preferable to just multiplying by 1 because you won't see the
"converted character to numeric" message.
Because you also have messages and other alpha characters, add a '??'
before the informat to suppress the error messages (those values will be
missing, or alternatively, you could specify another number or special
missing through your own informat):
numvar=input(charvar, ?? informat.);
> Is there an easy way to change a character variable
> to a numeric variable with the same varname ??
> The scenario is this:
> From an external source, data, which by nature is numeric,
> like laboratory values from blood analysis, is received
> in the format of a spreadsheet (eg. Excel). However, in
> a few (varying) records some of the variables v1-v99 does not
> contain numeric data (or are missing). Instead the vars contain
> tiny strings like 'NO' or 'NA' or 'N/A'. Bad dataentry behavior,
> but unfortunately accepted as input in the original spreadsheet.
> When converted to a SAS dataset (using eg. DBMS/COPY)
> any of the (logical) numeric vars for which just one record
> contain non-numeric data becomes a character-type variable,
> which is pretty much useless for calculations and 'formatted'
> I would dearly love a facility, whereby I could declare my
> logically numeric vars as numeric (in the SAS sense) vars. Of course,
> by consequence, vars containg non-numeric data would be missing
> (numerically missing) which is OK.
> Does anyone have a bright solution, either twisting the SAS syntax or
> employing a sophisticated (portable) macro ?????
> At the moment I have to create new, numeric vars, copy the old
> char vars contents to the new numeric vars, drop the original vars and
> then rename the new vars back to the old vars' names. There must be
> a smarter way ?