BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
meckarthik
Quartz | Level 8
Hi , I got two columns
1 aa
2 bb
3 cc

How to code in sas for combination
I want output to look like

1 aa
1 BB
2 aa
12 as
13 bb
123 aa
Etc
All possible combinations

Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data t1;
input letter1 $;
cards;
a1
b1
c1
;;;;
data t2;
input letter2 $;
cards;
a2
b2
c2
;;;;

proc sql;
create table want as
select t1.letter1, t2.letter2, catt(t1.letter1, t2.letter2) as comb
from t1, t2;
quit;

That's the quickest coding way.

View solution in original post

13 REPLIES 13
Reeza
Super User

How do you get 12 as?
What's the logic here, all combinations of a/b/c?

 


@meckarthik wrote:
Hi , I got two columns
1 aa
2 bb
3 cc

How to code in sas for combination
I want output to look like

1 aa
1 BB
2 aa
12 as
13 bb
123 aa
Etc
All possible combinations

Thanks

 

meckarthik
Quartz | Level 8
Hey, sorry typo error. Yes I want all combinations of a/b/c . That should also include abc1, bc1, 123abc etc. Let me know if it doesn't make sense
Reeza
Super User
What do you start out with exactly then?
meckarthik
Quartz | Level 8
I start with
Single match
1 a
2 a
Etc
Goes maximum 3 from column a and 3 from column b
Something like 3*3 matrices
123 ABC
123 acb
231 CBA
Whether it make sense
Thanks for helping on this

Reeza
Super User
You've gone from 2 matches, aa, ab, ac among three options to three way matches which is different.....so which is it?

meckarthik
Quartz | Level 8
So sorry it's two columns only
meckarthik
Quartz | Level 8
2 way match will do, thanks
Reeza
Super User
data t1;
input letter1 $;
cards;
a1
b1
c1
;;;;
data t2;
input letter2 $;
cards;
a2
b2
c2
;;;;

proc sql;
create table want as
select t1.letter1, t2.letter2, catt(t1.letter1, t2.letter2) as comb
from t1, t2;
quit;

That's the quickest coding way.

meckarthik
Quartz | Level 8

 Hi, expanded the query for 3 tables and it worked perfectly well. Just waiting for the final sign off!!!

meckarthik
Quartz | Level 8

& Thank you so much!

meckarthik
Quartz | Level 8
2 by 2 matrix only.
Reeza
Super User
I don't know what that means.
meckarthik
Quartz | Level 8
Thanks I will work on this and feedback.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 13 replies
  • 1358 views
  • 0 likes
  • 2 in conversation