BookmarkSubscribeRSS Feed
ayushupadhyay22
Calcite | Level 5

I am trying to combine three SAS data files using merge command using the following code.

 

proc sort data=orion.merger;
by ParcelNumber;

proc sort data=orion.merger1;
by ParcelNumber;
proc sort data=orion.merger2;
by ParcelNumber;


Data orion.mergermain;
merge orion.merger orion.merger1 orion.merger2;
by ParcelNumber;
run;

 

I have attached a screenshot of the log

 


2.png
2 REPLIES 2
art297
Opal | Level 21

You have to do a proc contents on the three files and see how the variables are defined in each file.

 

Where they conflict, if they are just duplicate values (but stored in a different data type) you can drop them (using the drop option) when using the merge statement (e.g., merge orion.whatever (drop=varxx varyyy) )

 

Art, CEO, AnalystFinder.com

 

Reeza
Super User

Are you sure you want a merge? Usually merges don't have the same variables in each dataset, or if they do, you need to rename the variables so they're unique in the final data set. You can't have multiple variables with the same name. 

 

I think you may want to concatenate/append the data instead. You'll have the same issue though, variables with the same name MUST have the same type in a single data set. 

http://support.sas.com/documentation/cdl/en/basess/68381/HTML/default/viewer.htm#p19t3r1gxavpoin14jd...

 

 

I show a method to identify which variables in are in which datasets here, but you can modify it to also show type. 

https://gist.github.com/statgeek/3b57ae085d9f7a36a2d95c15f04e72e6

 

 

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
  • 2 replies
  • 659 views
  • 0 likes
  • 3 in conversation