Hello,
I am merging 22 years of data sets in SAS 9.4 and I am getting several error statements saying variables such as sex, race, zipcode are defined a both character and numeric.
sex is M(male), F(female), U(unknown)
race is c 1(AIAN), 2(A), 3(BAA), 4(NHOPI), 5(W), 6(O), 7(U)
zipcode is continuous numbers
Will I have to rename these variables in each data set before I merge them?
This was my merging code:
data IHD9214;
set Ahca.Ihd1992 Ahca.Ihd1993 Ahca.Ihd1994 Ahca.Ihd1995 Ahca.Ihd1996 Ahca.Ihd1997 Ahca.Ihd1998 Ahca.Ihd1999 Ahca.Ihd2000 Ahca.Ihd2001 Ahca.Ihd2002 Ahca.Ihd2003 Ahca.Ihd2004 Ahca.Ihd2005 Ahca.Ihd2006 Ahca.Ihd2007 Ahca.Ihd2008 Ahca.Ihd2009 Ahca.Ihd2010 Ahca.Ihd2011 Ahca.Ihd2012 Ahca.Ihd2013 Ahca.Ihd2014;
run;
First of all, this is not a merge, it's a simple sequential set.
And yes, you need to have all variables of the same name to be of the same type (same length is not a must, but very advisable!).
So inspect your datasets and make the necessary changes before concatenating them.
This code may be useful in indicating which variable/datasets you need to be concerned with. It will create a report table with an X indicating which datasets have a variable of which type.
proc format library=work;
value x
1='X'
;
proc tabulate data=sashelp.vcolumn;
where libname='AHCA';
class memname name type;
tables name*type,
memname*n=''*f=x.
/misstext=' ';
run;
If these sets came from a common structure and were read with proc import then you may want to go back to reading the data with a method that will set consistent types and lengths.
Your error is likely to have issues with data truncation do to length differences as well.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.