String to numeric

Reply
Regular Contributor
Posts: 212

String to numeric

Hi, i'm trying to convert a string variable to numeric.

It's values are as follows:

valor.png

But when i convert to numeric with the code below:

VALOR_NEW=INPUT(TRIM(VALOR),BEST8.);

FORMAT VALOR_NEW COMMAX8.2;

There are only missing values.

I've tried to use all other number formats but it does not work.

Tks,

Rodrigo Dartibali Elias

Super User
Posts: 5,368

Re: String to numeric

Depends on the result you would want.  If you want the commas to be ignored, use:

valor_new = input(valor, comma8.);

If you want two positions after the decimal point every time, use:

valor_new = input(valor, comma8.2);

Good luck.

Frequent Contributor
Posts: 91

Re: String to numeric

It looks like there are commas in the amounts, like euro format.

Change the commas to periods.

valor=translate(valor,',','.');    Then the input function

Respected Advisor
Posts: 4,820

Re: String to numeric

Use COMMAX. on input, that's where the comma must be taken care of :

data test;

input str $;

x = input(str, commax32.);

format x best.;

datalines;

39,01

15,29

;

proc print;

run;

PG

PG
Ask a Question
Discussion stats
  • 3 replies
  • 220 views
  • 0 likes
  • 4 in conversation