BookmarkSubscribeRSS Feed
mlogan
Lapis Lazuli | Level 10

Hi All,

Can someone tell me the most efficient way to merge two dataset with multiple variable length (either by variable or other common variable to be merged). Is there a macro that will solve this problem for any variable within the dataset?

I defined the output variable length as follows, and it still does not work.

data test

length Country$ 12.;

merge one two;

by Country;

run;

NOTE: my right table (two) by variable length is 12 and left table (one) by variable length is 10

Thanks,

2 REPLIES 2
data_null__
Jade | Level 19

Are you sure it's an ERROR?

You just need to "fix" the lengths such that they match in both data sets or you could use the SAS system option to turn off the message and ignore this issue.

Perhaps someone has such a macro as you suggest or you can make your own.  Quite simple I should think.

M_Maldonado
Barite | Level 11

Hey mlogan,

I am sure you can find a macro to do this on google.

And Art Carpenter's book has a macro for EVERYHTING... Carpenter's Complete Guide to the SAS® Macro Language, Second Edition

If you don't have a lot of variables just choose a length.

Data mymerged;

length country $25;

merge dataone datatwo;

by commonid;

run;

When you have a chance, take the programming 1 class and this certification: SAS Global Certification: SAS Certified Base Programmer

Good luck,

Miguel

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to choose a machine learning algorithm

Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1114 views
  • 0 likes
  • 3 in conversation