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

Hi, I have a character variable which is about the surname of people. Many respondents entered the names as AA, BBB or ZZZZ which mean that they are not real names. So these cases should be deleted.

Translating this question into this: how can I check if a character variable consists of all same letters? Note that the name has varying length.

Thanks a lot for help.

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

another way:

data have;

  input name $20.;

  cards;

AA

BBB

ZZZZ

AABA

;

data want;

  set have;

  flag=compress(name,substr(name,1,1));

  if flag ne ' ';

run;

proc print;

run;

Linlin

View solution in original post

3 REPLIES 3
art297
Opal | Level 21

Here is one possibility:

data have;

  input name $20.;

  cards;

AA

BBB

ZZZZ

AABA

;

data want;

  set have;

  array chars(20);

  do i=1 to length(name);

    chars(i)=rank(substr(name,i,1));

  end;

  if min(of chars(*)) ne max(of chars(*)) then keepit=1;

  if keepit;

run;

Linlin
Lapis Lazuli | Level 10

another way:

data have;

  input name $20.;

  cards;

AA

BBB

ZZZZ

AABA

;

data want;

  set have;

  flag=compress(name,substr(name,1,1));

  if flag ne ' ';

run;

proc print;

run;

Linlin

DouglasMartin
Calcite | Level 5

This isn't an answer to your question (since the other two respondents gave solutions), but I just wanted to point out that if there is a possibility of pseudonyms like AAA, BBB, etc., I would assume there is also the possibility of pseudonyms like QWERTY, ASDFGH, 12345, etc. You are going to need a more elaborate filter than that (which can not possibly get rid of all pseudonyms without also potentially getting rid of some real names).

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1094 views
  • 6 likes
  • 4 in conversation