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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 809 views
  • 0 likes
  • 3 in conversation