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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 9161 views
  • 0 likes
  • 3 in conversation