BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Obsidian | Level 7
Hi All,
Can anyone please suggest me what to do if the data types is different in both the files while doing proc comparison.

Proc compare base=file1 compare=file2;
ID userid useritemid;

In the above example
File1 - userid as character
File2 - userid as numeric

File1-useritemid as character
File2-useritemid as numeric

Error message:the following 2 ID variables have inconsistent types in the base and comparison data sets;userid useritemid.

Can anyone suggest what to do in this case
Opal | Level 21

As you have seen, the PROC step won't execute under these conditions.  You would have to convert one or the other data set.  However, you don't need to create a new data set.  Instead, create a view and feed the view into PROC COMPARE.  One possibility (converting from character to numeric in the first file):

data file1_numeric / view=file1_numeric;
   set file1;
   temp_id = input(userid, 8.);
   temp_item = input(useritemid, 8.);
   drop userid useritemid;
   rename temp_id = userid;
   rename temp_item = useritemid;

Then run your PROC COMPARE with file1_numeric and file2.


Of course the best solution would be to user the same structure in both of your data sets originally.  And the second best solution would be to permanently convert your current data sets so they use the same structure.  But if you are looking for a third best solution, this would be a way to approach it.


You may run into other problems.  For example, perhaps some of the IDs were made character because they couldn't be stored as numeric.  Perhaps they contain letters.  You would have to examine the log for cases where the INPUT function gives you a message about invalid data.  When the INPUT function uses the 8. informat, it assumes that you have nothing longer than 8 digits.  If you have longer values, using a longer length in the INPUT function.

Obsidian | Level 7
Thankyou for the detailed explanation.
It worked for me thanks.



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg



Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1 like
  • 3 in conversation