BookmarkSubscribeRSS Feed
Lani
Calcite | Level 5
Hi all,

I am trying to remove "$", "," and then convert from char values to numeric values

amount (from input data)
$1,100.1
$1000
$59,000
$59

n_amount (the output)
1100.10
1000.00
59000.00
59.00

my codes:
attrib amount length=$10.
n_amount length=10.;

n_amount = input(amount,comma10.2);

However, the output I got:
n_amount
1100.1
10
590
0.59

Please help! Thank you.

-Lani
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Where is your INPUT statement logic to read up your data and assign a SAS character variable? It's best to share all your SAS code and ideally share it in a SAS session log (pasted in your post/reply).

You can add SAS PUTLOG _ALL_; commands to display all variable values - this may help you self-diagnose the situation.

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Hi Lani,

See here you are assigning the length of the string as 10 to the variable char Amount.
When you apply the comma10.2 to read it in input statement it will take the last two digits as the digits after decimal point.
for example:

data test;
input chars $10.;
cards;
$1,100.100
$1000.0000
$59,000.00
$59.000000
;
run;

data temp;
set test;
newnum=input(chars,dollar10.2);
run;
proc print;
run;


Running the above code will give you the right result. since the length is exactly 10 chars.

If you want to get the desired result on the data which you have provided just use comma10. or dollar10. format and not the decimal part of the formats.
Try following this code:

data test;
input chars $10.;
cards;
$1,100.1
$1000
$59,000
$59
;
run;

data temp;
format newnum 10.2;
set test;
newnum=input(chars,dollar10.);
run;
proc print;
run;



Thanks,
Saurabh. Message was edited by: emerald85

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 995 views
  • 0 likes
  • 3 in conversation