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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1466 views
  • 0 likes
  • 4 in conversation