DATA Step, Macro, Functions and more

Delete if wrds same in the word not by substr

Reply
Contributor
Posts: 37

Delete if wrds same in the word not by substr

data l;
input id $ 1-20;
cards;
aaaa1234a
bbbb1234b
ccccx1234c
asdf1234b
run;

I dont want to do by substr(1,1)=substr(2,1)


i want the output if the first character and last are same

output :

ccccx1234c
asdf1234b

Respected Advisor
Posts: 3,156

Re: Delete if wrds same in the word not by substr

Your output example seems inconsistent with your description, I will just go with the latter:

data l;

input id $ 1-20;

cards;

aaaa1234a

bbbb1234b

ccccx1234c

asdf1234b

run;

data want;

set l;

if first(id)=:left(reverse(id));

run;

proc print;run;

Haikuo

Valued Guide
Posts: 765

Re: Delete if wrds same in the word not by substr

hi ... another idea ...

data want;

set l;

where char(id,1) eq char(right(id),20);

run;

Super User
Posts: 10,018

Re: Delete if wrds same in the word not by substr

OR You like Perl Regular Expression :

data l;
input id $ 1-20;
cards;
aaaa1234a
bbbb1234b
ccccx1234c
asdf1234b
;
run;

 
data want;
set l;
where id=prxchange('s/(\S)(.*)(\S)/\3\2\1/o',-1,id);
run;

Ksharp

Contributor
Posts: 37

Re: Delete if wrds same in the word not by substr

Sory i have not framed my question properly

this is the req below

data l;
input id $ 1-20;
cards;
aaaa1234a
bbbb1234b
ccccx1234c
asdf1234b
run;

I dont want to do by substr(1,1)=substr(2,1)


i want the output if the first,second,third,foruth,fifth and last character and are not same.

output :

ccccx1234c
asdf1234b

Super User
Posts: 10,018

Re: Delete if wrds same in the word not by substr

My_SAS wrote:


i want the output if the first,second,third,foruth,fifth and last character and are same.

output :

ccccx1234c
asdf1234b

But in the case of 'ccccx1234c"

the first, -> c

second,-> c

third,-> c

foruth-> c

,fifth-> x

last character-> c

They are different . Any other logic are you using ?

Ksharp

Contributor
Posts: 37

Re: Delete if wrds same in the word not by substr

i want the output if the first,second,third,foruth,fifth and last character and are NOT same. 

output :

ccccx1234c
asdf1234b

Super User
Posts: 10,018

Re: Delete if wrds same in the word not by substr

Sorry . overlook "NOT"

Oh, I undertand what you mean now.

Ksharp

Contributor
Posts: 37

Re: Delete if wrds same in the word not by substr

should check only the characters are same not the numerics

bbbbb1234b

bbbbb      b (all the b characters are same in 1,2,3,4,5 and last obs are same)

Super User
Posts: 10,018

Re: Delete if wrds same in the word not by substr

How about:

data l;
input id $ 1-20;
cards;
aaaa1234a
bbbb1234b
ccccx1234c
asdf1234b
;
run;

 
data want(drop=x);
set l;
x=substrn(left(id),1,1);
if not missing (compress(id,x,'d')) ;
run;

Ksharp

Message was edited by: xia keshan

Ask a Question
Discussion stats
  • 9 replies
  • 339 views
  • 0 likes
  • 4 in conversation