Hello,
I have a list of variables:
data tab;
input var $;
datalines;
A
B
C
;
I need to create unique combinations of these variables:
| A | ||
| A | B | |
| A | B | C |
| A | C | |
| B | ||
| B | C | |
| C |
Thank you in advance for your help.
The simplest way is using proc means . Otherwise if you consider about efficient, then using GRAYCODE().
data tab;
input var $;
datalines;
A
B
C
;
run;
proc transpose data=tab out=temp(drop=_name_);
var var;
run;
proc summary data=temp;
class col:;
output out=want(where=(_type_ ne 0));
run;
Xia Keshan
Hi,
Something like:
data tab;
input var $;
datalines;
A
B
C
;
run;
proc transpose data=tab out=ttab;
var var;
run;
data want (keep=var1-var3);
set ttab;
length var1 var2 var3 $1;
array col{3};
array var{3};
do i=1 to 3;
var1=col{i};
output;
do j=i+1 to 3;
var{j}=col{j};
output;
end;
var1=""; var2=""; var3="";
end;
run;
Hi,
thank you for quick response.
I used your code but one combination is missing (A C)
Got a meeting now, will try to look later. I had got to this, needs sorting of the characters and then nodupkey sort:
data tab;
infile datalines missover;
input var $;
datalines;
A
B
C
;
run;
proc sql;
create table WANT as
select A.VAR as VAR1,
B.VAR as VAR2,
C.VAR as VAR3
from TAB A
full join TAB B
on A.VAR ne B.VAR
full join TAB C
on A.VAR ne C.VAR
and B.VAR ne C.VAR
union all
select VAR as VAR1,
"" as VAR2,
"" as VAR3
from TAB ;
quit;
The simplest way is using proc means . Otherwise if you consider about efficient, then using GRAYCODE().
data tab;
input var $;
datalines;
A
B
C
;
run;
proc transpose data=tab out=temp(drop=_name_);
var var;
run;
proc summary data=temp;
class col:;
output out=want(where=(_type_ ne 0));
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.