BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data test;
x='aabbeehvvkellb';
run;

How to find repeated characters in a string 

without use perl reg expression 

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

What do you want to do with repeated characters?

BrahmanandaRao
Lapis Lazuli | Level 10

Hi Draycut

Its is interview question 

ballardw
Super User

@BrahmanandaRao wrote:

Hi Draycut

Its is interview question 


In which I case I would say that the response would involve finding out from the questioner the purpose and explicit definition of "repeated characters" would be.

 

Consider if the purpose is to identify an explicit repeated series of characters such as "abc" in the string "123abc34abc".

Or a specific single character like "a" that could occur in "aa123aaa456aa9a". What would the rule be for what to do? Count that 'a' occurred 8 totals times  in the string, 7 times as part of sequences of 2 or more character or that it appeared in 3 sequences of  2 or more. Or just set a flag that something repeated?

Or are some or all of the repeated characters to be replaced? Moved into new/other variables ?

 

Different approaches to "finding" might be indicated for different actions to be taken on a string. If I need to manipulate a string then I need to rules so I know information I need to keep (likely temporary but still)

 

 

Ksharp
Super User

You could use COUNTC() .

n=countc(x,'a');

 

if n >=2 then there are repeated 'A' .

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!

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