I have 2 tables/datasets , I would like to merge Table 2 with Table 1 and arrive at the output table which looks like Table 3
Table 1 - time series table with year months from 2002 to 2010 (12 months * 9 years) , each Name1 goes for every month and year
Names1 | CompanyName | Code | YearMonth |
---|---|---|---|
A | XYZ | ||
A | ABC | ||
A | DEF | ||
B | XYZ | ||
B | EFH | ||
B | JKL | ||
B | DEF |
Table 2 (each CompanyName has four occurrences)
CompanyName | Code | EarningsDates |
---|---|---|
XYZ | Jan 2002 | |
XYZ | Apr 2002 | |
XYZ | July 2002 | |
XYZ | Nov 2002 |
Output table - Table 3 (I want all the columns of table 1) + the earnings dates to be populated for corresponding 'Code' variable.
Name1 | CompanyName | Code | Yearmonth | EarningsDates |
---|---|---|---|---|
A | xyz | Month1 | Jan 2002 | |
A | xyz | Month1 | Apr 2002 | |
A | xyz | Month1 | July 2002 | |
A | xyz | Month1 | Nov 2002 |
Thanks
Did you try just doing it? What happened?
This is a one to many merge.
The code is simple;
data table_3
merge table_1 table_2;
by name1 companyname;
run;
Pronabesh your code has a small error. He does not have name1 in data table_2, so remove that from your merge.
data table_3;
merge table_1 Table_2;
by companyname;
run;
Yes! Did not notice. Thanks for correcting that.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.