DATA Step, Macro, Functions and more

Variable XX has been defined as both character and numeric.

Reply
Contributor
Posts: 72

Variable XX has been defined as both character and numeric.

Hi,

 

I am trying to simply combine 5 tables (having the same variables),

 

 

libname XYZ "/sasdata/data/data3/Ali";

data XYZ.concatenation;
set XYZ.FBG_Analysis4 XYZ.FBG_ANALYSIS9 XYZ.FBG_ANALYSIS34 XYZ.FBG_ANALYSIS42

ERROR: Variable 'COT00503.D_SRVY'n has been defined as both character and numeric.

XYZ.FBG_ANALYSIS64;
run;

proc print data=XYZ.concatenation;
var C_ST C_DSTRB_AREA N_RSK ConstructionClass COT00503.C_CSP_CONST_CLS Current_FBG Updated_FBG Difference_percentage;
title 'Data Set CONCATENATION';
run;

 

 

But, I get this error. This variable 'COT00503.D_SRVY' is a "date" variable and I don't know how to solve the issue. Could you please help?

Super User
Posts: 17,905

Re: Variable XX has been defined as both character and numeric.

You need to look at that variable across all your tables. You'll find that one is a character and others are date, then you'll need to make them all the same in a separate step. Ideally, you can fix this in how you import your data if possible.

You can also query the SASHELP.VCOLUMN table to see where the issue is.

proc sql;
create table types as
select libnmae, memname, name, type as
from sashelp.vcolumn where
libname='XYZ' and memname in ("FBG_ANALYSIS4", "FBG_ANALYSIS9", "FBG_ANALYSIS34", "FBG_ANALYSIS42", "FBG_ANALYSIS64")
and name='COT00503.D_SRVY';
quit;

Contributor
Posts: 72

Re: Variable XX has been defined as both character and numeric.

Thank you Reeza. Could you please advise how to "make them all the same in a separate step" as you said?

Respected Advisor
Posts: 4,655

Re: Variable XX has been defined as both character and numeric.

[ Edited ]

Once you figure out which dataset contains the character date, you could fix it like this:

 

libname XYZ "/sasdata/data/data3/Ali";
data XYZ.concatenation;
set 
	XYZ.FBG_Analysis4 
	XYZ.FBG_ANALYSIS9 
		( rename='COT00503.D_SRVY'n=COT00503_D_SRVY_str 
		  in=special )
	XYZ.FBG_ANALYSIS34 
	XYZ.FBG_ANALYSIS42
	XYZ.FBG_ANALYSIS64;
if special then 'COT00503.D_SRVY'n = input(COT00503_D_SRVY_str, anydtdte.);
drop COT00503.D_SRVY_str;
run;

You might have to use a different informat.

PG
Ask a Question
Discussion stats
  • 3 replies
  • 239 views
  • 0 likes
  • 3 in conversation