Help using Base SAS procedures

replace '.' with ',' in a numeric column

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

replace '.' with ',' in a numeric column


Hi

Can any one help with following. (value in 'amt' column should be changed i.e,  '.' should be replaced by ',')

data have; 
name='alpha';amt=100090.23; output;
name='beta';amt=299999.12; output;
run;

data want;
name='alpha';amt='100090,23'; output;
name='beta';amt='299999,12'; output;
run;

Thanks in advance


Accepted Solutions
Solution
‎02-04-2015 02:27 AM
Super User
Posts: 10,046

Re: replace '.' with ',' in a numeric column

Add NUMXw.d format . You must come from somewhere of Euro ?

data have; 

name='alpha';amt=100090.23; output;

name='beta';amt=299999.12; output;

format amt numx12.2;

run;

Xia Keshan

View solution in original post


All Replies
Respected Advisor
Posts: 3,156

Re: replace '.' with ',' in a numeric column

Occasional Contributor
Posts: 19

Re: replace '.' with ',' in a numeric column

Thanks, but what I have is a numeric column with a decimal value and translate and tranwrd are useful for character columns.

Trusted Advisor
Posts: 1,934

Re: replace '.' with ',' in a numeric column

You want to assign the COMMAX format to this numeric variable.

Occasional Contributor
Posts: 19

Re: replace '.' with ',' in a numeric column

Posted in reply to PaigeMiller

@PaigeMiller: I just wanted to replace . with , and commax format also inserts period that separates every three digits.

But any ways, I converted the column to char and used translate, it works fine.

Super User
Super User
Posts: 7,997

Re: replace '.' with ',' in a numeric column

Numeric data does not allow commas, slashes, or any other special character other than -0123456789..  If you want to have comma's then you either need to apply a format - such as PaigeMiller has suggested - which basically applies a viewing format to the data which would remain unchanged, or convert the numeric data into a text field and then use textual replace functions on it.

data want;

     set have;

     length new_amt $20;

     new_amt=tranwrd(put(amt,best.),".",",");

run;

Solution
‎02-04-2015 02:27 AM
Super User
Posts: 10,046

Re: replace '.' with ',' in a numeric column

Add NUMXw.d format . You must come from somewhere of Euro ?

data have; 

name='alpha';amt=100090.23; output;

name='beta';amt=299999.12; output;

format amt numx12.2;

run;

Xia Keshan

Occasional Contributor
Posts: 19

Re: replace '.' with ',' in a numeric column

Thanks! thats perfect and also correct guess.

🔒 This topic is solved and locked.

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

Discussion stats
  • 7 replies
  • 273 views
  • 3 likes
  • 5 in conversation