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));
)
Another option:
data have;
input val $char12.;
val = translate(val, '.', ',');
val1 = input(val, trailsgn12.);
datalines;
100,008-
;
Try this.
data have;
input val comma9.;
val1=divide(val,-1000);
datalines;
100,008-
;
Another option:
data have;
input val $char12.;
val = translate(val, '.', ',');
val1 = input(val, trailsgn12.);
datalines;
100,008-
;
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.