BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Akshaya_1397
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.

Code:
Proc compare base=file1 compare=file2;
ID userid useritemid;
Run;

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
1 ACCEPTED SOLUTION
3 REPLIES 3
Astounding
PROC Star

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;
run;

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.

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

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 16. 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
  • 3 replies
  • 713 views
  • 1 like
  • 3 in conversation