BookmarkSubscribeRSS Feed
factorhedge
Fluorite | Level 6

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

Names1CompanyNameCodeYearMonth
AXYZ
AABC
ADEF
BXYZ
BEFH
BJKL
BDEF

Table 2 (each CompanyName has four occurrences)

CompanyNameCodeEarningsDates
XYZJan 2002
XYZApr 2002
XYZJuly 2002
XYZNov 2002

Output table - Table 3 (I want all the columns of table 1) + the earnings dates to be populated for corresponding 'Code' variable.

Name1CompanyNameCodeYearmonthEarningsDates
AxyzMonth1Jan 2002
AxyzMonth1Apr 2002
AxyzMonth1July 2002
AxyzMonth1Nov 2002

Thanks

4 REPLIES 4
Tom
Super User Tom
Super User

Did you try just doing it?  What happened?

pronabesh
Fluorite | Level 6

This is a one to many merge.

The code is simple;

data table_3

     merge table_1 table_2;

     by name1 companyname;

run;

Anotherdream
Quartz | Level 8

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;

pronabesh
Fluorite | Level 6

Yes! Did not notice. Thanks for correcting that.

sas-innovate-2024.png

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.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 4 replies
  • 1451 views
  • 0 likes
  • 4 in conversation