## How to convert the character string including percentage and numbers into numeric data?

Solved
Frequent Contributor
Posts: 102

# How to convert the character string including percentage and numbers into numeric data?

Hello

I have character strings which including percentage and numbers. how do I convert them into numeric data?

my data is

var

45.5%

34

23.64%

23

44.56%

798

I use the code:

data a;

set a;

if var=:"%" then var1=input(var,percent8.);

else var1=input(var,best8.);

run;

But it does not work.

Thanks a lot!

Accepted Solutions
Solution
‎06-16-2017 09:50 PM
Trusted Advisor
Posts: 1,174

## Re: How to convert the character string including percentage and numbers into numeric data?

I tried as below and it works

``````data have;
input var\$10.;;
cards;
45.5%
34
23.64%
23
44.56%
798
;

data want;
set have;
if index(var,'%') then new=input(var,percent.);
else new=input(var,best.);
run;
``````
Thanks,
Jag

All Replies
Solution
‎06-16-2017 09:50 PM
Trusted Advisor
Posts: 1,174

## Re: How to convert the character string including percentage and numbers into numeric data?

I tried as below and it works

``````data have;
input var\$10.;;
cards;
45.5%
34
23.64%
23
44.56%
798
;

data want;
set have;
if index(var,'%') then new=input(var,percent.);
else new=input(var,best.);
run;
``````
Thanks,
Jag
Frequent Contributor
Posts: 102

## Re: How to convert the character string including percentage and numbers into numeric data?

Posted in reply to Jagadishkatam
Thank you very much!
Super User
Posts: 24,028

## Re: How to convert the character string including percentage and numbers into numeric data?

The =: only checks if the variables start with that character string, not contains. ie does it start with a percentage sign. To check if hte variable contains a % sign you would use FIND or INDEX.

🔒 This topic is solved and locked.

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

Discussion stats
• 3 replies
• 943 views
• 2 likes
• 3 in conversation