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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.