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.
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
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;
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
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).
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.