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' .

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1197 views
  • 1 like
  • 5 in conversation