BookmarkSubscribeRSS Feed
india2016
Pyrite | Level 9

I have 2 dataset described below name correct data and incorrect data. Now i want to map incorrect data from correct data.

For example in incorrect data for adarsh nagar station circle is incorrect and for harmara station police district is incorrect.

I have used proc sort by station for both the table and then i have used IN= option but it wokrs for just one variable but i want to map data using for both variable i.e. circle and station.

 

Correct Data Incorrect data
DistrictCircleStation DistrictCircleStation
EASTADARSH NAGARADARSH NAGAR EASTCHOMUADARSH NAGAR
EASTADARSH NAGARJAWAHAR NAGAR EASTADARSH NAGARJAWAHAR NAGAR
WESTCHOMUHARMARA WESTCHOMUHARMARA
WESTCHOMUVISHWAKARMA EASTCHOMUVISHWAKARMA
6 REPLIES 6
LinusH
Tourmaline | Level 20

Please show a desired output to further describe your requirement.

Data never sleeps
india2016
Pyrite | Level 9
input district :$10. circle :$20. station :$20.;
cards;
east adarshnagar adarshnagar
east adarshnagar jawaharnagar
east gandhinagar gandhinagar
west chomu harmara
west chomu vishwakarma
;
run;
data incorrect;
infile cards;
input district :$10. circle :$20. station :$20.;
cards;
east chomu adarshnagar
east adarshnagar jawaharnagar
west chomu harmara
east chomu vishwakarma
;
run;
india2016
Pyrite | Level 9
This is my program that i had done

proc sort data=WORK.CORRECT;
by station;
run;
proc sort data=WORK.INCORRECT;
by station;
run;

data match mismatch;
merge WORK.CORRECT(in=PC) WORK.INCORRECT(in=PS1 rename=(Circle=Circle1 district=district1));
by station;
if PC;
if district eq district1 and Circle eq Circle1 then output match;
if district ne district1 and Circle ne Circle1 then output mismatch;
run;
india2016
Pyrite | Level 9
This is what i am getting in output for match
district,circle,station,district1,Circle1
west,chomu,harmara,west,chomu
east,adarshnagar,jawaharnagar,east,adarshnagar



Output for mismatch

district,circle,station,district1,Circle1
east,gandhinagar,gandhinagar,,


Match is correct but i am not getting correct data for mismatch
Kurt_Bremser
Super User

Maybe you should slightly change the second condition:

data match mismatch;
merge WORK.CORRECT(in=PC) WORK.INCORRECT(in=PS1 rename=(Circle=Circle1 district=district1));
by station;
if PC;
if district eq district1 and Circle eq Circle1 then output match;
if district ne district1 or Circle ne Circle1 then output mismatch;
run; 

or make it even simpler:

data match mismatch;
merge WORK.CORRECT(in=PC) WORK.INCORRECT(in=PS1 rename=(Circle=Circle1 district=district1));
by station;
if PC;
if district eq district1 and Circle eq Circle1
then output match;
else output mismatch;
run; 
Kurt_Bremser
Super User

Please post example data in a data step, like

data correct;
infile cards dlm=',';
input district :$4. circle :$20. station :$20.;
cards;
EAST,ADARSH NAGAR,ADARSH NAGAR
EAST,ADARSH NAGAR,JAWAHAR NAGAR
WEST,CHOMU,HARMARA
WEST,CHOMU,VISHWAKARMA
;
run;

This makes it easier for us to recreate your data.

A macro that does this automatically cam be found at https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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