## How to convert Character data with trailing sign to Numeric data

Solved
Occasional Contributor
Posts: 18

# How to convert Character data with trailing sign to Numeric data

[ Edited ]

Hi All,

I have a requirement where the input is coming from the Easytrieve in which the acceptable numeric format is 100.00-. I need to convert this into  SAS numeric format. Can some one help me in achieving this?

Input            Output

100.00-        -100.00

This field is the variable one.

Accepted Solutions
Solution
‎02-27-2018 04:51 AM
Super User
Posts: 10,849

## Re: How to convert Character data to Numeric data.

``````data x;
input x trailsgn32.;
cards;
100.00-
34.32-
29
64.89
;
run;
proc print;run;``````

All Replies
Posts: 5,621

## Re: How to convert Character data to Numeric data.

``````
/* Informat function to read numbers possibly suffixed with a
minus sign. */
proc fcmp outlib=work.fcmp.format;
function EasytrieveNumber(text \$);
m = indexc(text, "-");
if m = length(text) then return (-input(substr(text,1,m-1), best.));
else return (input(text, best.));
endsub;
run;

options cmplib=(work.fcmp);

proc format;
invalue EasytrieveNumber(default=32)
OTHER = [EasytrieveNumber()];
run;

data have;
input a :EasytrieveNumber10.;
format a 8.2;
cards;
100.00-
100.00
;

proc print data=have; run;``````
```                                  Obs           a

1      -100.00
2       100.00
```
PG
Solution
‎02-27-2018 04:51 AM
Super User
Posts: 10,849

## Re: How to convert Character data to Numeric data.

``````data x;
input x trailsgn32.;
cards;
100.00-
34.32-
29
64.89
;
run;
proc print;run;``````
Occasional Contributor
Posts: 18

## Re: How to convert Character data to Numeric data.

Hi Ksharp,

TRAILSGNw. will only work for numeric values. In this case the input is coming as 100.00- which in my knowledge will only be read as a character value.

Thanks!

Regular Contributor
Posts: 226

## Re: How to convert Character data to Numeric data.

@SASInd: @Ksharp demonstrates that the format can be used to create normal numbers.

Occasional Contributor
Posts: 18

## Re: How to convert Character data to Numeric data.

Thank you @Ksharp @error_prone & @Reeza

Occasional Contributor
Posts: 18

## Re: How to convert Character data to Numeric data.

Yeah... But the question here is for converting the character data to a numeric format.
Super User
Posts: 23,987

## Re: How to convert Character data to Numeric data.

Yeah... But the question here is for converting the character data to a numeric format.

That's what @Ksharp solution does, you can use that format in the INPUT() statement.

``````data x;
input x \$;
cards;
100.00-
34.32-
29
64.89
;
run;

data want;
set x;
char_x=input(x, trailsgn32.);
run;

proc print data=want;
run;``````
☑ This topic is solved.