SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Trailsgn Informat if decimal mark is a comma

Accepted Solution Solved
Reply
Super Contributor
Posts: 340
Accepted Solution

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,167

Re: Trailsgn Informat if decimal mark is a comma

Posted in reply to user24feb

Another option:

data have;

input val $char12.;

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

val1 = input(val, trailsgn12.);

datalines;

100,008-

;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,228

Re: Trailsgn Informat if decimal mark is a comma

Posted in reply to user24feb

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,167

Re: Trailsgn Informat if decimal mark is a comma

Posted in reply to user24feb

Another option:

data have;

input val $char12.;

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

val1 = input(val, trailsgn12.);

datalines;

100,008-

;

Super Contributor
Posts: 340

Re: Trailsgn Informat if decimal mark is a comma

Smiley Happy  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.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 541 views
  • 3 likes
  • 3 in conversation