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

 

Hi, Maybe  a very simple quesion, but it puzzles me. I want to compare two variables with different names in two data sets. How can I do it? for example, I want to compare a in data set one with d in data set two. I check the 'proc compare', but it compares the whole data set. thank you .

data one;
input a
cards;
6
5
6
7
;
run;
data two;
input d;
cards;
7
8
5
2
;
run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

What is the meaning of those two variables? What output you want to get?

 

You said that: 

I check the 'proc compare', but it compares the whole data set.

you can use proc compare as:

proc compare base=one (keep=a)
               compare=two(keep=d rename=(d=a));
run;

If it doesn't satisfy you, explain why and what are you expecting.

 

Besides you wrote:

 I just want to compare the two variables to identify if they can be used as ID  

should't the IDs be unique? How do you know when they fit that they have same meaning and can be used as IDs ?

View solution in original post

10 REPLIES 10
PeterClemmensen
Tourmaline | Level 20

What do you mean by compare? Do you want to subtract them from each other? And do you not have some ID variable, this will usually be the case when comparing variables.

lixuan
Obsidian | Level 7

No ,  I just want to compare the two variables to identify if they can be used as ID  which can be used to merge the two data sets.

Shmuel
Garnet | Level 18

What is the meaning of those two variables? What output you want to get?

 

You said that: 

I check the 'proc compare', but it compares the whole data set.

you can use proc compare as:

proc compare base=one (keep=a)
               compare=two(keep=d rename=(d=a));
run;

If it doesn't satisfy you, explain why and what are you expecting.

 

Besides you wrote:

 I just want to compare the two variables to identify if they can be used as ID  

should't the IDs be unique? How do you know when they fit that they have same meaning and can be used as IDs ?

lixuan
Obsidian | Level 7

Your code is helpful. The ID should be unique. I am merging different stock data, but different database has their own ID system, so i want to know if they are same. Thks$ regards

RW9
Diamond | Level 26 RW9
Diamond | Level 26

" I want to compare two variables with different names in two data sets." - I am sorry, could you explain what you mean/want as output?  You say you don't want to compare the whole dataset, so what exactly is it you want to compare?  Proc compare would obviously be first choice, just rename d to a:

proc compare base=one compare=two (rename=(d=a));
run;

 

lixuan
Obsidian | Level 7

Sure , I have two datasets with different variables, and I want to merge both, but I dont konw which variables can be use as ID, so i want to compare the variables. 

lixuan
Obsidian | Level 7

OK, I think proc compare is a better result, because it gives me a summary report. also, by using sql i can get the details. Thank you all very much.

ballardw
Super User

You didn't show the Proc Compare code you used. If the variables are different names in the two sets you can use something like this:

 

proc compare base=one compare=two;

   var a;

   with d;

run;

 

to restrict the comparison to specific variables and only compare the ones of interest.

Since you looking a suitability as a matching variable you might want to sort the data sets by the candidate variable for better results.

 

lixuan
Obsidian | Level 7
Thank you , I don't konw proc compare code can be folllowed by var. yours answer is the simpliest.

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!

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
  • 10 replies
  • 5894 views
  • 1 like
  • 6 in conversation