Programming the statistical procedures from SAS

merge datasets

Reply
Contributor
Posts: 24

merge datasets

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

Super User
Super User
Posts: 6,701

Re: merge datasets

Did you try just doing it?  What happened?

Contributor
Posts: 58

Re: merge datasets

This is a one to many merge.

The code is simple;

data table_3

     merge table_1 table_2;

     by name1 companyname;

run;

Super Contributor
Posts: 418

Re: merge datasets

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;

Contributor
Posts: 58

Re: merge datasets

Yes! Did not notice. Thanks for correcting that.

Ask a Question
Discussion stats
  • 4 replies
  • 303 views
  • 0 likes
  • 4 in conversation