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
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
hi ... another idea ...
data want;
set l;
where char(id,1) eq char(right(id),20);
run;
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
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
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
i want the output if the first,second,third,foruth,fifth and last character and are NOT same.
output :
ccccx1234c
asdf1234b
Sorry . overlook "NOT"
Oh, I undertand what you mean now.
Ksharp
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)
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
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 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.