To join multiple tables in SAS EG about 5 tables the primary key is different in some so cannot join. The report is prepared in excel and have to replicate it but the fields are set up in different tables. Can you show me a query where I can perform joins, where the primary key is missing in some cannot join them.
@Sultana wrote:
To join multiple tables in SAS EG about 5 tables the primary key is different in some so cannot join. The report is prepared in excel and have to replicate it but the fields are set up in different tables. Can you show me a query where I can perform joins, where the primary key is missing in some cannot join them.
Can you post some examples of how you want that to be handled? If the key isn't there what record gets matched? Or what gets included. Please show what you have as starting data and what you want as output and explain the logic, then we can either suggest an approach or code. But without more information this is a vague question, which gets a vague answer.
To include data please see:
Before you get into a complex query, perhaps a simple example might clarify things a bit.
Here's a simple one-to-many join that shows the idea.
Tom
data Customers;
length CustomerID 8 CustomerName $20 ContactName $20 Address $30 City $15 PostalCode $10 Country $10;
input CustomerID & CustomerName & ContactName & Address & City & PostalCode & Country &;
cards;
1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany
2 Ana Trujillo Emparedados y helados Ana Trujillo Avda. de la Constitución 2222 México D.F. 05021 Mexico
3 Antonio Moreno Taquería Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
run;
data Orders;
informat OrderDate yymmdd10.;
input OrderID CustomerNumber EmployeeID OrderDate ShipperID;
cards;
10308 2 7 1996-09-18 3
10309 37 3 1996-09-19 1
10310 77 8 1996-09-20 2
10311 2 9 1996-09-21 4
run;
proc sql noprint;
create table OrdersAndCustomers as
select Orders.OrderID, Orders.OrderDate, Customers.CustomerID, Customers.CustomerName
from Orders inner join Customers on Orders.CustomerNumber = Customers.CustomerID;
quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.