From: Arthur Tabachneck on
Dan,

I presume you meant "rather than the old INPUT() method." I'm not on 9.2
yet but, regardless, you might be interested in the macro (from SAS) that
can be found on Paul Dickman's page:

http://www.pauldickman.com/teaching/sas/char_to_num.php

HTH,
Art
--------
On Sat, 20 Feb 2010 09:46:23 -0500, Dan Abner <dan.abner99(a)GMAIL.COM>
wrote:

>Hello all,
>
>Does 9.2 offer any better way to convert CHAR vars to NUM than the old PUT
()
>method?
>
>I ask b/c I have a large number of vars to convert and they are presently
in
>the correct order (VARNUM) in the data set?
From: Joe Matise on
Not at a computer with SAS so there may be some typos here but:

data have;
input x $ y $ z $;
datalines;
1 2 3
5 4 3
2 3 1
5 5 4
;;;;
run;

proc sql;
select cats('%rename(',var,')') into :renamelist separated by ' '
from dictionary.columns where memname='HAVE' and type='C' order by varnum;
*not sure on some of these variable names, but they're there in the
dictionary.columns somewhere;
select cats('%convert(',var,')') into :convertlist separated by ' '
from dictionary.columns where memname='HAVE' and type='C' order by varnum;
quit;
%macro rename(Var);
rename=&var=&Var._c
%mend rename;
%macro convert(var);
format &var. BEST12.;
&var = input(&var._c,BEST12.);
%mend convert;
data want;
set have(&renamelist);
&convertlist;
run;

Something to that effect, allowing for typos and forgetfulness. Obviously
have your own restriction determining what qualifies as a variable to
rename.

-Joe
On Sat, Feb 20, 2010 at 8:46 AM, Dan Abner <dan.abner99(a)gmail.com> wrote:

> Hello all,
>
> Does 9.2 offer any better way to convert CHAR vars to NUM than the old
> PUT()
> method?
>
> I ask b/c I have a large number of vars to convert and they are presently
> in
> the correct order (VARNUM) in the data set?
>
From: Sigurd Hermansen on
The ordering of variables wouldn't matter if you combine the well known and reliable INPUT() method for converting character type variables in SAS datasets to numeric type variables. Assuming that your character type variables contain the expected elements of numbers:

Proc sql;
/* Convert numeric values to character values. */
create table class as
select PUT(Height,z8.) as Height,PUT(Weight,z8.) as Weight,*
from SASHELP.class
;
Select 'INPUT('||strip(name)||',8.) as '||name into :putvars separated by ','
From dictionary.columns where libname='WORK' and memname='CLASS'
and index(name,'eight')
;
create table class as
select &putvars ,* from class
;
quit;

S
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Dan Abner
Sent: Saturday, February 20, 2010 9:46 AM
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: SAS 9.2 CHAR to NUM

Hello all,

Does 9.2 offer any better way to convert CHAR vars to NUM than the old PUT()
method?

I ask b/c I have a large number of vars to convert and they are presently in
the correct order (VARNUM) in the data set?
From: Joe Matise on
How do you ensure they're selected in the right order? Is
dictionary.columns necessarily ordered by variable name?

On Sat, Feb 20, 2010 at 2:58 PM, Sigurd Hermansen <HERMANS1(a)westat.com>wrote:

> The ordering of variables wouldn't matter if you combine the well known and
> reliable INPUT() method for converting character type variables in SAS
> datasets to numeric type variables. Assuming that your character type
> variables contain the expected elements of numbers:
>
> Proc sql;
> /* Convert numeric values to character values. */
> create table class as
> select PUT(Height,z8.) as Height,PUT(Weight,z8.) as Weight,*
> from SASHELP.class
> ;
> Select 'INPUT('||strip(name)||',8.) as '||name into :putvars separated by
> ','
> From dictionary.columns where libname='WORK' and memname='CLASS'
> and index(name,'eight')
> ;
> create table class as
> select &putvars ,* from class
> ;
> quit;
>
> S
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Dan
> Abner
> Sent: Saturday, February 20, 2010 9:46 AM
> To: SAS-L(a)LISTSERV.UGA.EDU
> Subject: SAS 9.2 CHAR to NUM
>
> Hello all,
>
> Does 9.2 offer any better way to convert CHAR vars to NUM than the old
> PUT()
> method?
>
> I ask b/c I have a large number of vars to convert and they are presently
> in
> the correct order (VARNUM) in the data set?
>