I have 2 datasets. In one dataset we have correct data for example: states falls in country variable. and in another dataset we have incorrect data for example few of the states falls into wrong country. I want to check that incorrect data. How to do that??
Try this:
data correct;
input country :$20. state :$20.;
cards;
US Nevada
Austria Tirol
US California
;
run;
data dubious;
input country :$20. state :$20.;
cards;
UK Nevada
Austria Tirol
France California
;
run;
proc sort data=correct;
by state;
run;
proc sort data=dubious;
by state;
run;
data checked;
merge
dubious (in=d)
correct (in=c rename=(country=_country))
;
by state;
if d;
if c and country ne _country then country = _country;
drop _country;
run;
proc print data=checked noobs;
run;
This results in:
country state US California US Nevada Austria Tirol
I need only incorrect data.
Simple change, you should be able to find this yourself:
data checked;
merge
dubious (in=d)
correct (in=c rename=(country=_country))
;
by state;
if d;
if c and country ne _country;
run;
The result now is this:
country state _country France California US UK Nevada US
Thanks. Its working.
Just to repeat what @ballardw said:
"It is a very good idea to provide some example data and the final result for your example data."
Don't make us do all your work for you.
Use the macro provided here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... to convert your example dataset into a data step for posting here.
It is a very good idea to provide some example data and the final result for your example data.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.