data test;
x='aabbeehvvkellb';
run;
How to find repeated characters in a string
without use perl reg expression
What do you want to do when you find a repeat? Remove the character, or just flag the observation?
What do you want to do with repeated characters?
Hi Draycut
Its is interview question
That does not answer our questions.
WHAT DO YOU WANT TO DO WHEN YOU FIND A REPEAT?
@BrahmanandaRao wrote:
Hi Draycut
Its is interview question
@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)
You could use COUNTC() .
n=countc(x,'a');
if n >=2 then there are repeated 'A' .
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.