BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
archita
Fluorite | Level 6
I have two datasets with common variables station and station number in both.. I want to see distinct common station with same city name and also common station with different city name.please help.
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Run this:

data Test1;
input name $ number;
datalines;
Alex 301
Tor 78
Seine 200
Ron 450
Alex 301
;

data Test2;
input name $ number;
datalines;
Ran 65
Tor 78
Alex 209
Manik 34
Tor 44
;

proc sort data=test1;
by name;
run;

proc sort data=test2;
by name;
run;

data
  match
  nomatch
  miss_1
  miss_2
;
merge
  test1 (in=t1 rename=(number=number1))
  test2 (in=t2 rename=(number=number2))
;
by name;
if t1 and t2
then do;
  if number1 = number2
  then output match;
  else output nomatch;
end;
else if t2
then output miss_1;
else output miss_2;
run;

and see if the results are what you need, otherwise tell us what you need to be different.

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Please provide some sample data.

archita
Fluorite | Level 6
Test1
Alex 301
Tor 78
Seine 200
Ron 450
Alex 301
Test2.
Ran 65
Tor 78
Alex 209
Manik 34
Tor 44


PeterClemmensen
Tourmaline | Level 20

And given this data, what does your desired result look like?

archita
Fluorite | Level 6
 
archita
Fluorite | Level 6
I want to see common variables with same records and also common variables with different record
Like Alex 301 I'm first case and
Alex 209 for second one
Kurt_Bremser
Super User

Run this:

data Test1;
input name $ number;
datalines;
Alex 301
Tor 78
Seine 200
Ron 450
Alex 301
;

data Test2;
input name $ number;
datalines;
Ran 65
Tor 78
Alex 209
Manik 34
Tor 44
;

proc sort data=test1;
by name;
run;

proc sort data=test2;
by name;
run;

data
  match
  nomatch
  miss_1
  miss_2
;
merge
  test1 (in=t1 rename=(number=number1))
  test2 (in=t2 rename=(number=number2))
;
by name;
if t1 and t2
then do;
  if number1 = number2
  then output match;
  else output nomatch;
end;
else if t2
then output miss_1;
else output miss_2;
run;

and see if the results are what you need, otherwise tell us what you need to be different.

archita
Fluorite | Level 6
Thank you working fine .

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 1743 views
  • 0 likes
  • 3 in conversation