BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
UMAnalyst
Obsidian | Level 7

 

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

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

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

4 REPLIES 4
slchen
Lapis Lazuli | Level 10
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;
stat_sas
Ammonite | Level 13

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;

UMAnalyst
Obsidian | Level 7

Thank you for your help. I love this forum.

PGStats
Opal | Level 21

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

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.

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