BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lucas
Calcite | Level 5

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
AB
ABC
AC
B
BC
C

Thank you in advance for your help.


1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

The simplest way is using proc means . Otherwise if you consider about efficient, then using GRAYCODE().

Code: Program

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

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Lucas
Calcite | Level 5

Hi,

thank you for quick response.

I used your code but one combination is missing (A C)

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

Ksharp
Super User

The simplest way is using proc means . Otherwise if you consider about efficient, then using GRAYCODE().

Code: Program

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1109 views
  • 1 like
  • 3 in conversation