Hi All,
I am trying to create a dataset from a file such that if party has already in cluster it can not be a part of any other cluster.
Party1 party2
1 2
1 7
2 1
2 8
3 5
3 8
7 3
8 7
So basically we will start by smallest party1 and all corresponding party2 for that party1 are part of cluster.
But for party1= 1 , 2 and 7 are already part of cluster hence all cases with party1 syartist with 2and 7 will be eliminated and smallest next party 1will be considered for cluster .so next cluster will be 3 and so on
If I understood your question.
data have;
input Party1 party2;
cards;
1 2
1 7
2 1
2 8
3 5
3 8
7 3
8 7
;
run;
data want;
if _n_=1 then do;
if 0 then set have;
declare hash h();
h.definekey('party2');
h.definedone();
end;
set have;
if h.check(key:party1)=0 then delete;
h.replace();
run;
proc print;run;
You've shown us the input data, and made a description of the requirements.
Help us help you. Show how you want the result data set or table to appear.
Does your example data implies that 1, 2, 3, 5, 7, 8 are all part of the same cluster?
If I understood your question.
data have;
input Party1 party2;
cards;
1 2
1 7
2 1
2 8
3 5
3 8
7 3
8 7
;
run;
data want;
if _n_=1 then do;
if 0 then set have;
declare hash h();
h.definekey('party2');
h.definedone();
end;
set have;
if h.check(key:party1)=0 then delete;
h.replace();
run;
proc print;run;
Hi Ksharp ,
your response is perfect as per my concern but I missed to highlight one scenario in my query.
data have;
input Party1 party2;
cards;
1 2
1 7
2 1
2 8
2 9
3 5
3 8
7 3
8 7
9 1
;
run;
I have included one more row in cluster for prty1=2 i.e. 2 9
Actually I want to excude all rows starting with prty2 values for my valid cluster.
since cluster starting with part1 =1 is valid cluster hence
all rows satrting with 2 and 7 will be discarded.
But since cluster starting with 2 was never considered to be a valid cluster
so prty2 values for this cluster rows will not be considered for row elimnation
so my final op will be something like
Party1 party2;
1 2
1 7
3 5
3 8
9 1
Thanks a ton in advance!!!!!!!!!!!!!!!!!!!!!!!
OK. How about this one ?
data have;
input Party1 party2;
cards;
1 2
1 7
2 1
2 8
2 9
3 5
3 8
7 3
8 7
9 1
;
run;
data want;
if _n_=1 then do;
if 0 then set have;
declare hash h();
h.definekey('party2');
h.definedone();
end;
set have;
if h.check(key:party1)=0 then delete;
else h.replace();
run;
proc print;run;
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.