🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 08-23-2018 01:57 AM
(3581 views)
I ran the following code and end up with error as follows. Could you please help me with the format which translate comma values to percent? I don't wish to do any data manipulation here.
data foo;
format y percent7.1;
y=-0,01259870;
run;
proc print data=foo;
run;
Log:
26 data foo;
27 format y percent7.1;
28 y=-0,01259870;
_
388
200
ERROR 388-185: Expecting an arithmetic operator.
ERROR 200-322: The symbol is not recognized and will be ignored.
Desired output:
1.3%
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You cannot write code using that non-standard method of using commas to replace decimal points.
But you can use the COMMAX informat to read strings that are written that way.
data test ;
input @1 string $12. @1 number commax12. ;
percent=number;
format percent percent7.1 ;
put (_all_) (=/);
cards;
-0,01259870
;
string=-0,01259870 number=-0.0125987 percent=( 1.3%)
7 REPLIES 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
you should use dot instead of comma
please try
data foo;
format y percent7.1;
y=-0.01259870;
run;
proc print data=foo;
run;
please try
data foo;
format y percent7.1;
y=-0.01259870;
run;
proc print data=foo;
run;
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
No, I no need to convert comma to dot. I have values in my file like -0,01259870
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
then please something as below
data foo;
format y percent7.1;
y=input(tranwrd('-0,01259870',',','.'),best.);
run;
proc print data=foo;
run;
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Is there anyway to deal this with only formats?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
As per my understanding functions would be a best approach, alternatively you could create a customized function by proc fcmp
Thanks,
Jag
Jag
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You cannot write code using that non-standard method of using commas to replace decimal points.
But you can use the COMMAX informat to read strings that are written that way.
data test ;
input @1 string $12. @1 number commax12. ;
percent=number;
format percent percent7.1 ;
put (_all_) (=/);
cards;
-0,01259870
;
string=-0,01259870 number=-0.0125987 percent=( 1.3%)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Or
data test ; input number numx12. ; format number percent15.5 ; cards; -0,01259870 ; run;