I need to create a dummy variable that flags cases who lived at the same address in 2012 as in 2010.
Data looks like:
ID year fulladdress
1000001 2010 101 STREET NUM CITY ST ZIP
1000001 2012 101 STREET NUM CITY ST ZIP
1000002 2010 999 STREET NUM CITY ST ZIP
1000002 2012 777 STREET NUM CITY ST ZIP
.
.
.
Thanks for your help
proc sql;
create table want as
select *,case when count(distinct fulladdress)=1 then 'Same' else 'Different' end as
flag from have group by id;
quit;
data want;
merge have have(firstobs=2 rename=(id=_id year=_year fulladdress=_fulladdress));
if id=_id and compbl(fulladdress)=compbl(_fulladdress) then flag=1;
drop _:;
run;
proc sql;
create table want as
select *,case when count(distinct fulladdress)=1 then 'Same' else 'Different' end as
flag from have group by id;
quit;
Thank you for your help. I love this forum.
Without assuming the list is limited to 2010 and 2012 addresses :
proc sql;
create table want as
select
*,
id in (
select a.id from have as a inner join have as b
on a.id=b.id and a.fullAddr=b.fullAddr
where a.year=2010 and b.year=2012) as sameAddr
from have;
quit;
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.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.