BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sapkota
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Hima
Obsidian | Level 7

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;

Capture.JPG

View solution in original post

9 REPLIES 9
Hima
Obsidian | Level 7

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;

Capture.JPG

Hima
Obsidian | Level 7

what are you trying to merge?

Sapkota
Calcite | Level 5

I am trying to merge two different datasets of chemicals that have numeric values. Both these datasets have a common variable lab_id.

ballardw
Super User

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).

Sapkota
Calcite | Level 5

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

ballardw
Super User

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.

Sapkota
Calcite | Level 5

That is a good option. Thanks!

ballardw
Super User

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.

Sapkota
Calcite | Level 5

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 9 replies
  • 1128 views
  • 11 likes
  • 3 in conversation