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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.