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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.