DATA Step, Macro, Functions and more

convert money format to numeric format with decimal places

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 120
Accepted Solution

convert money format to numeric format with decimal places

Hi ,

I have data with variable x which has values

$105.00
$120.00
$135.00
$15.00

$1.39

 

how to convert to  numeric number format with decimal places

 105.00
120.00
135.00
15.00

 

can anyone pls help


Accepted Solutions
Solution
‎03-24-2016 02:57 PM
Super User
Posts: 17,864

Re: convert money format to numeric format with decimal places

If you want to change the format, apply a new format. 

 

INPUT/PUT are for type conversions -> character to numeric or numeric to character.

 

format variable 8.2;

Here's a fully worked example.

 

data have;
retain actual sample1 sample3 predict sample2;
set sashelp.prdsal2(obs=20);
sample1=actual;
sample2=predict;
sample3=floor(actual); *Round down to 0 decimal places;

format sample1 8.2;
format sample2 8.;
format sample3 8.2;

keep actual sample1 sample3 predict sample2;
run;

proc print data=have;
run;

 

 

View solution in original post


All Replies
Frequent Contributor
Posts: 120

Re: convert money format to numeric format with decimal places

Currently to achieve I am using below code

 

(input(put(X,10.4),10.2)) AS XY

 

but I am getting

105
120
135
15

1.39

but i am not getting zeros

Solution
‎03-24-2016 02:57 PM
Super User
Posts: 17,864

Re: convert money format to numeric format with decimal places

If you want to change the format, apply a new format. 

 

INPUT/PUT are for type conversions -> character to numeric or numeric to character.

 

format variable 8.2;

Here's a fully worked example.

 

data have;
retain actual sample1 sample3 predict sample2;
set sashelp.prdsal2(obs=20);
sample1=actual;
sample2=predict;
sample3=floor(actual); *Round down to 0 decimal places;

format sample1 8.2;
format sample2 8.;
format sample3 8.2;

keep actual sample1 sample3 predict sample2;
run;

proc print data=have;
run;

 

 

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 571 views
  • 0 likes
  • 2 in conversation