SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Babloo
Rhodochrosite | Level 12

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
Tom
Super User Tom
Super User

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

View solution in original post

7 REPLIES 7
Jagadishkatam
Amethyst | Level 16
you should use dot instead of comma
please try

data foo;
format y percent7.1;
y=-0.01259870;
run;
proc print data=foo;
run;
Thanks,
Jag
Babloo
Rhodochrosite | Level 12

No, I no need to convert comma to dot. I have values in my file like -0,01259870

Jagadishkatam
Amethyst | Level 16

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
Babloo
Rhodochrosite | Level 12
Is there anyway to deal this with only formats?
Jagadishkatam
Amethyst | Level 16
As per my understanding functions would be a best approach, alternatively you could create a customized function by proc fcmp
Thanks,
Jag
Tom
Super User Tom
Super User

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%)
ballardw
Super User

Or

data test ;
  input number numx12. ;
  format number percent15.5 ;
cards;
-0,01259870
;
run;

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 3582 views
  • 4 likes
  • 4 in conversation