joinsasconcatenationappend

How to join all rows of one table to a column of another table that is not in the first table?


First table is only one column, just customer ID:

ID
___
1122
2222
3333

Second table is the product information:

    | State| User   | Limit
    | CA   | JM21   | 100
    | OH   | JD11   | 200 
    | WV   | KM34   | 250

I need to join all product information to each customer ID. My question is if there is a way to cross join all the data from the second table to each individual row in the first table?

I want the final table to look like:

|ID |State | User   | Limit
1122| CA   | JM21   | 100
1122| OH   | JD11   | 200 
1122| WV   | KM34   | 250
2222| CA   | JM21   | 100
2222| OH   | JD11   | 200 
2222| WV   | KM34   | 250

Thanks!


Solution

  • Yes, use the CROSS JOIN join.

    data one ; input id@@; datalines ;
    1122 2222 3333
    ;
    data two; input State $ User $ Limit ; datalines ;
    CA JM21 100
    OH JD11 200 
    WV KM34 250
    ;
    proc sql ;
      create table want as 
      select one.*, two.*
      from one cross join two 
      ;
    

    enter image description here

    Learn more from the documentation joined-table Component