I have a column in which I want to check the similarity of the values. I want to delete those values whose first 10 characters are the same as the first 10 characters of some other value.
I thought I could solve it with two nested loops and a Compare function. But unfortunately it doesn't work.
Could someone help me?
You should post sample data as a data step, like this:
Data have;
infile cards truncover;
input txt $20.;
cards;
1234567890a
1234567890b
z1234567890a
z1234567890a432
;run;
One possible solution is to sort and compare:
proc sort data=have;
by txt;
run;
data want;
set have;
if lag(substr(txt,1,10)) ne substr(txt,1,10);
run;
Are these "values" on the same observation? Nested do loops imply data step code and such a data step basically only wants to work on one observation at a time.
Provide example data in the form of a working data step and the expected result. Paste the code for the data step into a text box opened with the </> icon as the main message window reformats pasted text and the result may not actually run.
This does what you asked for:
I want to delete those values whose first 10 characters are the same as the first 10 characters of some other value.
proc sql ;
create table want as
select * from have
group by substr(COLUMN,1,10)
having count(*)=1
;
quit;
But I suspect you actually want something different.
You should post sample data as a data step, like this:
Data have;
infile cards truncover;
input txt $20.;
cards;
1234567890a
1234567890b
z1234567890a
z1234567890a432
;run;
One possible solution is to sort and compare:
proc sort data=have;
by txt;
run;
data want;
set have;
if lag(substr(txt,1,10)) ne substr(txt,1,10);
run;
@Neptun83 wrote:
Thank you guys. I can solve the problem .
Great. But please report your solution, and mark it as the answer to your question (or just mark the "I can solve the problem" as the answer).
Then the rest of us will not think this is a question still looking for an answer.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.