SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

create dummy to flag obs w/ same address at two time points

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

create dummy to flag obs w/ same address at two time points

 

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


Accepted Solutions
Solution
‎11-16-2015 06:55 AM
Trusted Advisor
Posts: 1,204

Re: create dummy to flag obs w/ same address at two time points

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;

View solution in original post


All Replies
Super Contributor
Posts: 275

Re: create dummy to flag obs w/ same address at two time points

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;
Solution
‎11-16-2015 06:55 AM
Trusted Advisor
Posts: 1,204

Re: create dummy to flag obs w/ same address at two time points

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;

Occasional Contributor
Posts: 14

Re: create dummy to flag obs w/ same address at two time points

Thank you for your help. I love this forum.

Respected Advisor
Posts: 4,651

Re: create dummy to flag obs w/ same address at two time points

[ Edited ]

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;
PG
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 338 views
  • 2 likes
  • 4 in conversation