BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
daszlosek
Quartz | Level 8

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

Another way

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

View solution in original post

5 REPLIES 5
Reeza
Super User

There's no difference in your Have/Want

kiranv_
Rhodochrosite | Level 12

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

kiranv_
Rhodochrosite | Level 12

Another way

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 3959 views
  • 1 like
  • 5 in conversation