BookmarkSubscribeRSS Feed
Jahanzaib
Quartz | Level 8

I want to merge two data sets on the basis of company name and year. The two data sets have same company name and same number of years but different variables. Can anyone here help me?

1 REPLY 1
Reeza
Super User

1. Sort by variables you'll be merging on

2. Merge via data step or SQL

 

Before you do, consider what type of merge you want. Is this a one to one match - each record in table 1 has an exat match in table 2?

Or do you want all records from one table? What if there's no match?

 

The documentation is very helpful in walking you through a merge and multiple different types of combining data. Here's the link to the Match Merge docs.

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1tgk0uanvisvon1r26l...

 

proc sort data=data1; by company_name year;
proc sort data=data2; by company_name year;

data want;
merge data1 data2;
by company_name year;
run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 629 views
  • 0 likes
  • 2 in conversation