BookmarkSubscribeRSS Feed
nwang5
Obsidian | Level 7

Hi,

 

I hope you are doing well. I am trying to combine the dataset and it shows the error:  Variable has been defined as both character and numeric. How can I solve it?

 

 

 

70 data hrslong.hrs;
71 merge
72 randhrs (in=a)
73 h92 (in=b) h93 (in=c) h94 (in=d) h95 (in=e) h96 (in=f) h98 (in=g)
74 h00 (in=h) h02 (in=i) h04 (in=j) h06 (in=k) h08 (in=l) h10 (in=m) h12 (in=n) h14 (in=o)
75 h16 (in=p) h18 (in=q);
ERROR: Variable AHHID has been defined as both character and numeric.
ERROR: Variable ASUBHH has been defined as both character and numeric.
ERROR: Variable BPPN has been defined as both character and numeric.
ERROR: Variable APPN has been defined as both character and numeric.
ERROR: Variable CPPN has been defined as both character and numeric.
ERROR: Variable ESUBHH has been defined as both character and numeric.
ERROR: Variable APPN has been defined as both character and numeric.
ERROR: Variable BPPN has been defined as both character and numeric.
ERROR: Variable CPPN has been defined as both character and numeric.
ERROR: Variable APPN has been defined as both character and numeric.
ERROR: Variable BPPN has been defined as both character and numeric.
ERROR: Variable CPPN has been defined as both character and numeric.
76 if a=1;
77 by hhidpn;
78 run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set HRSLONG.HRS may be incomplete. When this step was stopped there were 0
observations and 119681 variables.
WARNING: Data set HRSLONG.HRS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.43 seconds
cpu time 0.32 seconds

2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

  Well, in your merge, you are essentially bringing together many different datasets. The error message is clear. You cannot have the same variable defined a character in one or more than one of the files and the same-named variable defined as numeric in one or more than one of the files.

  I would recommend that you do a PROC CONTENTS on all the data sets used in your MERGE. Find out which datasets define the variables as numeric and which datasets define the variables as character. You are the only one who knows which data type is correct. The error message shows you the variable names. Once you decide which data type is correct for the listed variables (Character or Numeric), then you'll need to fix the data files before the merge so that all the variables are the correct type when they come into the DATA step with the MERGE.

  It looks like all your input data is in the WORK library, which implies that you had some previous program that created each of these files. You may need to go back to the program where the "bad" type was defined and fix the issue there. I think the best approach is to fix the issue at the first point where you read or create each of these files that are coming into the MERGE -- much better to fix it up front, so that all subsequent uses of the files have the correct type. Basically, your MERGE is not going to work until you fix the mismatched types.

 

Cynthia

Tom
Super User Tom
Super User

Are you using this RAND HRS data?  https://hrsdata.isr.umich.edu/data-products/rand

How did you create the work datasets you are using in that merge?  You must have done something to have created the variables inconsistently across the files.  Take a step back in your code to the point where RANDHRS and H92 etc are created and make sure that you are defining the variables the same way everywhere they appear.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 588 views
  • 2 likes
  • 3 in conversation