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

I want to compare 2 datasets without using proc compare procedure. How to do that?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@FabeehaSheikh1 wrote:

nothing wrong with proc compare. This was one of the interview questions. I want to compare all variables and values it contains in the dataset without using proc compare. Hence, this question.


In an interview question my response would start with the "what do you want to know" from the comparison.

Some of the table properties are in Dictionary.tables for Proc SQL (or sashelp.vtables for other procs).

Variable properties in Dictionary.columns or sashelp.vcolumns .

Value comparisons get into, most likely some form of Proc SQL or Data step merge/update/modify or similar,l depending on the actual questions about the values. Big difference in approaches of if the question involves equality of values, specific combinations of values or something like how close are the values such as comparing the results of two different models where you "know" the values of the predicted variable(s) are likely to differ but by how much. (Which might well be doable inside the modeling proc if careful).

 

No reason to go into a lot of code for other things that aren't needed/wanted to answer specific questions.

View solution in original post

4 REPLIES 4
ballardw
Super User

Depends on what you want to find out about the two data  sets. Properties of the data set such as number of observations, numbers of variables. Or about variables such as common or different variables or different characteristics for same named variables? Or values/ combinations of values ?

 

And what is wrong with proc compare? I know there are things we may want to do that compare doesn't do, or not easily, but

FabeehaSheikh1
Fluorite | Level 6

nothing wrong with proc compare. This was one of the interview questions. I want to compare all variables and values it contains in the dataset without using proc compare. Hence, this question.

ballardw
Super User

@FabeehaSheikh1 wrote:

nothing wrong with proc compare. This was one of the interview questions. I want to compare all variables and values it contains in the dataset without using proc compare. Hence, this question.


In an interview question my response would start with the "what do you want to know" from the comparison.

Some of the table properties are in Dictionary.tables for Proc SQL (or sashelp.vtables for other procs).

Variable properties in Dictionary.columns or sashelp.vcolumns .

Value comparisons get into, most likely some form of Proc SQL or Data step merge/update/modify or similar,l depending on the actual questions about the values. Big difference in approaches of if the question involves equality of values, specific combinations of values or something like how close are the values such as comparing the results of two different models where you "know" the values of the predicted variable(s) are likely to differ but by how much. (Which might well be doable inside the modeling proc if careful).

 

No reason to go into a lot of code for other things that aren't needed/wanted to answer specific questions.

aayo
Obsidian | Level 7

Hi Fabeeha,

check this.

 

proc sql;

create table mismatch as
select * from tableA
where ID not in (select ID from tableB );
quit;

 

N.B: ID is the unique identifier you want to use to compare

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1224 views
  • 0 likes
  • 3 in conversation