BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
user24feb
Barite | Level 11

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));

)

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

Another option:

data have;

input val $char12.;

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

val1 = input(val, trailsgn12.);

datalines;

100,008-

;

View solution in original post

3 REPLIES 3
stat_sas
Ammonite | Level 13

Try this.

data have;

input val comma9.;

val1=divide(val,-1000);

datalines;

100,008-

;

TomKari
Onyx | Level 15

Another option:

data have;

input val $char12.;

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

val1 = input(val, trailsgn12.);

datalines;

100,008-

;

user24feb
Barite | Level 11

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;









sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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