Hi,
I am merging two datasets and one of them is in character format.
I applied few SAS procedures to change the character to number value before merging
but when I merge it still says 'Error: variable has been defined as both character and numeric'.
Here is what I tried, but with both of these I still get the error messages:
data temp1; set temp;
var1_n = var1*1;
var2_n=var2*1;
va3_n=var3*1;
run;
data temp1; set temp;
var1_n = input(var1, 3.);
var2_n = input (var2, 3.);
var3_n = input (var3, 3.);
run;
Any help and will be appreciated. Thanks
DATA HAVE;
INPUT ID $;
DATALINES;
1
2
3
4
;
RUN;
PROC CONTENTS DATA=HAVE; RUN;
DATA WANT;
SET HAVE;
ID_NEW=INPUT(ID,3.);
RUN;
PROC CONTENTS DATA=WANT; RUN;
DATA HAVE;
INPUT ID $;
DATALINES;
1
2
3
4
;
RUN;
PROC CONTENTS DATA=HAVE; RUN;
DATA WANT;
SET HAVE;
ID_NEW=INPUT(ID,3.);
RUN;
PROC CONTENTS DATA=WANT; RUN;
what are you trying to merge?
I am trying to merge two different datasets of chemicals that have numeric values. Both these datasets have a common variable lab_id.
I think it is time to run proc contents on both temp and chemicals. Look for the same variable name but different data type. That would be your culprit(s).
Yes, running proc content helped in knowing the numeric and character variables. What was coming on the way of the merger was the persistence of the character variable after the new numeric variable were created. I dropped the character variables and that yielded to the merger. Thanks
You could also just rename them on the merge
data example
merge set1 (rename=(var1=CharVar1))
set2
;
run;
As an example if var1 was a variable with different types.
That is a good option. Thanks!
If you have more than the three variables shown you may be having issues with one of them.
You don't show any merging code so it is a tad hard to give pointers where to look.
Thanks. Here is the merging code I used. Please note that the dataset 'chemicals' already has numerical values. Its only the dataset 'temp1' where values need to be converted to numeric.
data merged;
merge temp1 (in=x) chemicals;
by lab_id;
if x;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.