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

Hi Everyone,

   I have one dataset which has one variable, containing a person's name and another dataset with a list of training courses and I was wondering if there is a quick way to create a third dataset which would contain a record for each possible person and training combination.  The two datasets do not have a common variable.  Keep in mind that we may not know how many of each we have at any time, and the data can change constantly.  For example:

 

Dataset A:

Name

 Abby

Bobby

Chris

 

Dataset B:

Training

Training #1

Training #2

 

Desired Dataset:

Name        Training

Abby          Training #1

Abby          Training #2

Bobby        Training #1

Bobby        Training #2

Chris          Training #1

Chris          Training #2

 

  Any thoughts?

 

Thanks!

 

-Phil

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

It's called a cartesian join or cross join.

 

 

proc sql;

create table want as

select *

from a,b;

quit;

View solution in original post

3 REPLIES 3
Reeza
Super User

It's called a cartesian join or cross join.

 

 

proc sql;

create table want as

select *

from a,b;

quit;

Phil0917
Fluorite | Level 6

Thanks!  That worked perfectly!  It did give me a "NOTE: The execution of this query involves performing one or
more Cartesian product joins that can not be optimized." message, but it did seem to create all of the desired records.

FriedEgg
SAS Employee

 

data a;
input name $;
cards;
abby
bobby
chris
;
run;

data b;
length training $ 11;
input training &;
cards;
training #1
training #2
;
run;

data c;
set a;
do _n_=1 to nobs;
  set b nobs=nobs point=_n_;
  output;
end;
run;

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
  • 3 replies
  • 947 views
  • 2 likes
  • 3 in conversation