## How to remove periods from a string with digits in decimal place

Solved
Frequent Contributor
Posts: 78

# How to remove periods from a string with digits in decimal place

[ Edited ]

Hello all,

I am trying to pull a string out from a free text. I was able to use the substring and find function to pull out the specific area around the string. but there are periods marking the end of a sentence that I would like to remove. Not all rows have a period at the end (my assumption would be I could use compress, but then any decimals would be removed as well.

For example:

11.5

12

10.

10.2.

And I would like:

11.5

12

10

10.2

I was thinking maybe I could use the find function to find the second period and then delete? Any suggestions would be much appreciated.

EDIT: My apologies, I forgot to remove the string

Accepted Solutions
Solution
‎10-17-2017 03:12 PM
PROC Star
Posts: 499

## Re: How to remove periods from a string with digits in decimal place

Another way

``````data abc;
input a \$;
b=prxchange('s/^(.+?)(\.)*\$/\$1/', -1,trim(a));
datalines;
10.2
10.2.
10
10.3...
run;``````

All Replies
Super User
Posts: 22,850

## Re: How to remove periods from a string with digits in decimal place

There's no difference in your Have/Want

PROC Star
Posts: 499

## Re: How to remove periods from a string with digits in decimal place

your example and what you want are same. so you want dot removed at the end of string?

Super User
Posts: 9,211

## Re: How to remove periods from a string with digits in decimal place

I agree with the other posters, your test data is wrong.  One solution:

```data want;
set have;
if char(thestring,lengthn(thestring)-1)="." then thestring=substr(thestring,1,lengthn(thestring)-1);
run;
```

As you haven't provided test data in the form of a datastep I have made up a variable thestring.

Solution
‎10-17-2017 03:12 PM
PROC Star
Posts: 499

## Re: How to remove periods from a string with digits in decimal place

Another way

``````data abc;
input a \$;
b=prxchange('s/^(.+?)(\.)*\$/\$1/', -1,trim(a));
datalines;
10.2
10.2.
10
10.3...
run;``````
Super User
Posts: 10,618

## Re: How to remove periods from a string with digits in decimal place

``````data abc;
input a \$;
b=prxchange('s/\.+\$//', -1,trim(a));
datalines;
10.2
10.2.
10
10.3...
run;``````
☑ This topic is solved.