Learning SAS? Welcome to the exclusive online community for all SAS learners.

how to convert char data to numeric data with formats

Reply
Contributor
Posts: 40

how to convert char data to numeric data with formats

hi friends,

      i have the data set like this

data test;

t_name               val

tx_map_c            52

tx_acc                 25,943

tx_par                  98.3%

tx_rc                     0

ter_txt                   5.6%

tx_pzc                  192,386

tx_pcc                   192

tx_r                       9

tcp                        2,259,736

how to convert  char data to numeric data with formats

plz help.................

 

Super User
Posts: 17,801

Re: how to convert char data to numeric data with formats

A variable can only have one format applied, what format do you want to apply? And how would you know what format to apply?

Super User
Posts: 17,801

Re: how to convert char data to numeric data with formats

PROC Star
Posts: 1,090

Re: how to convert char data to numeric data with formats

Taking a stab at what you want...

data have;

tx_map_c = '52';

tx_acc = '25,943';

tx_par = '98.3%';

tx_rc = '0';

ter_txt = '5.6%';

tx_pzc = '192,386';

tx_pcc = '192';

tx_r = '9';

tcp = '2,259,736';

output;

run;

data want;

set have;

cx_map_c = input(tx_map_c, best20.);

cx_acc = input(tx_acc, comma20.);

cx_par = input(tx_par, percent20.);

cx_rc = input(tx_rc, best20.);

cer_txt = input(ter_txt, percent20.);

cx_pzc = input(tx_pzc, comma20.);

cx_pcc = input(tx_pcc, best20.);

cx_r = input(tx_r, best20.);

ccp = input(tcp, comma20.);

run;

Contributor
Posts: 40

Re: how to convert char data to numeric data with formats

t_name and val both are char data type

Super User
Super User
Posts: 7,401

Re: how to convert char data to numeric data with formats

So whats the problem then, you have just stated that val is all one format, text, which can hold any of the data.  TomKari has given you code to convert each one to a numeric variable?  If you mean you want some to be percentage and others not, then this is not possible.  SAS is a structured format, a column has one format.  SAS != Excel!  If you need some with percentage, some without then you need more than one variable, although your could just store the number, and in any output i.e. proc report, conditionally format the number by using compute blocks.

Ask a Question
Discussion stats
  • 5 replies
  • 471 views
  • 0 likes
  • 4 in conversation