BookmarkSubscribeRSS Feed
crc7rb
Calcite | Level 5

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;

 

3 REPLIES 3
Kurt_Bremser
Super User

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.

Reeza
Super User
Do all the files have the same variables and types? Did you happen to import these files from an XLSX or CSV/txt file?
ballardw
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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