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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1424 views
  • 3 likes
  • 4 in conversation