BookmarkSubscribeRSS Feed
Rik
Calcite | Level 5 Rik
Calcite | Level 5
Hi,

I want to create a dataset with information coming out of multiple datasets Let me try to explain with an example;

Data ONE;
infile cards;
attrib COUNTRY length=$20 label='Country';
input country;
cards;
Belgium
France
Germany
;
run;
Data TWO;
infile cards;
attrib STOCK length=$20 label='Stock';
input country;
cards;
Stock1
Stock2
;
run;
Data THREE;
infile cards;
attrib PRODUCT length=$20 label='Product';
input country;
cards;
Product1
Product2
;
Run;

Now I want to create a dataset with all possible combinations of the above data set. This should look like this.
COUNTRY STOCK PRODUCT
--------------- ------------- ----------------
Belgium Stock1 Product1
Belgium Stock1 Product2
Belgium Stock2 Product1
Belgium Stock2 Product2
France Stock1 Product1
France Stock1 Product2
France Stock2 Product1
France Stock2 Product2
Germany Stock1 Product1
Germany Stock1 Product2
Germany Stock2 Product1
Germany Stock2 Product2


Not sure how to handle this.
Any suggestions?

Thanks.
3 REPLIES 3
Patrick
Opal | Level 21
What you want is a cartesian product. That's easiest done with SQL:

Data ONE;
infile cards;
attrib COUNTRY length=$20 label='Country';
input country;
cards;
Belgium
France
Germany
;
run;
Data TWO;
infile cards;
attrib STOCK length=$20 label='Stock';
input STOCK;
cards;
Stock1
Stock2
;
run;
Data THREE;
infile cards;
attrib PRODUCT length=$20 label='Product';
input PRODUCT;
cards;
Product1
Product2
;
Run;

proc sql;
select *
from THREE,(select * from one ,two)
;
quit;
Rik
Calcite | Level 5 Rik
Calcite | Level 5
How simple can it be?

Thanks for your help!
Pavan_SAS
SAS Employee
proc sql;
select * from one,two,three;
quit;

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