03-14-2017 05:41 AM - last edited on 03-18-2017 04:08 PM by KurtBremser
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??
03-14-2017 06:04 AM
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
03-14-2017 07:39 AM
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
03-18-2017 06:23 AM
03-18-2017 08:33 AM
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.