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!!!
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?
Correct. ![]()
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;
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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.