DATA Step, Macro, Functions and more

2*2 paring

Reply
Contributor
Posts: 25

2*2 paring

Hello everyone,

I have a list of providers, and I want to create a second dataset with each provider paired with one other provider. A provider will not be paired to itself.

table have

provider_id

a

b

c

d

e

....

table want

provider id1         provider id2

a                           b

a                           c

a                           d

a                           e

b                           c

b                           d

b                           e

c                            d

c                            e

d                            e

Thanks advance for all the inputs!!!

Super User
Posts: 11,343

Re: 2*2 paring

Posted in reply to cindyforest7

It appears that you have a second requirement that if the a-b pair has been generated that you do not want b-a. Is that correct?

Contributor
Posts: 25

Re: 2*2 paring

Correct. Smiley Happy

Trusted Advisor
Posts: 1,228

Re: 2*2 paring

Posted in reply to cindyforest7

data have;

input provider_id $;

datalines;

a

b

c

d

e

;


proc sql;

create table want as

select a.provider_id as provider_id1, b.provider_id as provider_id2 from have a

cross join have b

where a.provider_id<b.provider_id;

quit;

Super User
Posts: 10,028

Re: 2*2 paring

Posted in reply to cindyforest7

You are trying to get all the combination of ID . OR try to use function  COMB() .

data have;
input provider_id $;
datalines;
a
b
c
d
e
;
run;
data want;
 set have end=last;
 array x{9999999} $ _temporary_;
 x{_n_}=provider_id;
 if last then do;
  do i=1 to _n_-1;
   do j=i+1 to _n_;
     id1=x{i};id2=x{j};output;
   end;
  end;
end;
keep id1 id2;
run;


Xia Keshan

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