## Trailsgn Informat if decimal mark is a comma

Solved
Super Contributor
Posts: 353

# Trailsgn Informat if decimal mark is a comma

Hello,

is there a possibility to read data that has the trailing minus and a decimal seperator that is "," instead of "."?

For example:

100,008- should give -100.008 (="minus one-hundred-point-zero-zero-eight" and NOT "minus hundred-thousand-and-eight"; that´s why Trailsgn15.3 does not work)

Thanks & kind regards

(My best guess would be (if TS is the input variable), but I am not really happy with this:

Sign=Index(TS,'-')/Index(TS,'-');

If Sign eq 1 Then Number=(Input(Substr(TS,1,Length(TS)-1),Commax15.3))*-1;

Else Number=(Input(TS,Commax15.3));

)

Accepted Solutions
Solution
‎07-07-2014 10:12 AM
PROC Star
Posts: 1,288

## Re: Trailsgn Informat if decimal mark is a comma

Another option:

data have;

input val \$char12.;

val = translate(val, '.', ',');

val1 = input(val, trailsgn12.);

datalines;

100,008-

;

All Replies
Posts: 1,270

## Re: Trailsgn Informat if decimal mark is a comma

Try this.

data have;

input val comma9.;

val1=divide(val,-1000);

datalines;

100,008-

;

Solution
‎07-07-2014 10:12 AM
PROC Star
Posts: 1,288

## Re: Trailsgn Informat if decimal mark is a comma

Another option:

data have;

input val \$char12.;

val = translate(val, '.', ',');

val1 = input(val, trailsgn12.);

datalines;

100,008-

;

Super Contributor
Posts: 353

## Re: Trailsgn Informat if decimal mark is a comma

Thanks.

I think TomKari is right, some text pre-processing (with "translate" or so) can´t be avoided. (Sorry, I didn´t mention that there are both values with and without a trailing minus). I will use: Number2=Input(Compress(Translate(Translate(TS,'','.'),'.',',')),TrailSgn15.);

(In this case ',' is the decimal and '.' the thousands seperator).

Data A;
Input TS \$20.;
Sign=Index(TS,'-');
If Sign ge 1 Then Number=(Input(Substr(TS,1,Length(TS)-1),Commax15.3))*-1;
Else Number=(Input(TS,Commax15.3));
Format Number 15.4;

/* without Substr: */
Number2=Input(Compress(Translate(Translate(TS,'','.'),'.',',')),TrailSgn15.);
Format Number2 15.4;

Datalines;

100,008

100,008-

1555,458
1555,458-

2,04
2,04-
4.000,4
4.000,4-
112.000,4
112.000,4-
123.456.789,012
123.456.789,012-
;
Run;

🔒 This topic is solved and locked.