BookmarkSubscribeRSS Feed
InnovativeMinds
Fluorite | Level 6

Hi, I have two input datasets and I want to create an output dataset like mentioned below. Thanks so much for your help and time.

 

1st input dataset:

key1key2
101901
101902
101903
101904
101905
102801
102802
102803
102804

 

2nd Input Dataset:

key1key3key4var1var2var3var4var5varn
101a1b1......
101a2b2......
101a3b3......
102a4b4......
102a5b5......
102a6b6......

 

Output dataset:

key2key1key3key4var1var2var3var4var5varn
901101a1b1......
901101a2b2......
901101a3b3......
902101a1b1......
902101a2b2......
902101a3b3......
903101a1b1......
903101a2b2......
903101a3b3......
801102a4b4......
801102a5b5......
801102a6b6......
802102a4b4......
802102a5b5......
802102a6b6......
803102a4b4......
803102a5b5......
803102a6b6......
804102a4b4......
804102a5b5......
804102a6b6......

 

Thanks Again!

John

4 REPLIES 4
Jagadishkatam
Amethyst | Level 16

You are trying to get a cartesian product which is possible by proc sql as below

 

data have1;
input key1	key2;
cards;
101	901
101	902
101	903
101	904
101	905
102	801
102	802
102	803
102	804
;
 

data have2;
input key1	key3$	key4$	var1	var2	var3	var4	var5	varn;
cards;
101	a1	b1	.	.	.	.	.	.
101	a2	b2	.	.	.	.	.	.
101	a3	b3	.	.	.	.	.	.
102	a4	b4	.	.	.	.	.	.
102	a5	b5	.	.	.	.	.	.
102	a6	b6	.	.	.	.	.	.
;


proc sql;
create table want as select a.*,b.key2 from have2 as a left join have1 as b on a.key1=b.key1 order by a.key1,b.key2;
quit;
Thanks,
Jag
ChrisNZ
Tourmaline | Level 20

Why is there no key2=905 in the output?

InnovativeMinds
Fluorite | Level 6
Chris, sorry that missed 904&905. Thanks for the catch!
InnovativeMinds
Fluorite | Level 6
Thanks Jagadishkatam.

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
  • 1041 views
  • 0 likes
  • 3 in conversation