BookmarkSubscribeRSS Feed
chris2377
Quartz | Level 8

Hi,

 

I have a number of datasets (ds1, ds2, ds3, etc) that I want to append. However, several variables have different types (i.e. character or numeric) in different datasets, so when I use:

 

data new;

set ds:;

run;

 

I get the error message "Variable var1 has been defined as both character and numeric" etc.

 

Is there a way to append the datasets and have all the variables without manually changing their types? They could all be stored as character

 

Best

3 REPLIES 3
Shmuel
Garnet | Level 18
Is there a way to append the datasets without changing types? 

NO, same variable cannot have different types.

 

Decide which type is proffered and change the type on the appropriate datasets or rename them to have different names. 

ballardw
Super User

One of the most common causes of this is use of Proc Import to read data. That means that you have no control over the variable types or lengths. If these data sets are supposed to be of the same structure you will be better off the long run by reading the data as needed, likely with a data step.

 

You can also have issues with variables of the same type with different lengths. So if you are seeing notes related to that then you should also fix the length issues before combining the data.

tomrvincent
Rhodochrosite | Level 12
I convert all the numeric fields in each table to string and then union them together.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2256 views
  • 3 likes
  • 4 in conversation