BookmarkSubscribeRSS Feed
cindyforest7
Calcite | Level 5

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!!!

4 REPLIES 4
ballardw
Super User

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?

cindyforest7
Calcite | Level 5

Correct. Smiley Happy

stat_sas
Ammonite | Level 13

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;

Ksharp
Super User

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1314 views
  • 0 likes
  • 4 in conversation