BookmarkSubscribeRSS Feed
mikeed
Calcite | Level 5

I'm examining a dataset where everyone within the same household has the same ID, but different person numbers (PNUM).

 

They also have marital status pointers that point to PNUMs of their spouses.

 

I want to check if a persons spouse has some other condition.

 

What's the best way of going about this?

2 REPLIES 2
Reeza
Super User
proc sql;
create table want as
select t1.*, t2.condition as spouse_condition
from have as t1
left join have as t2
on t1.spouse_num = t2.num;
quit;

 A self join/merge is what you want. Merge the data on the Spouses ID and then pull through the condition variable.

 


@mikeed wrote:

I'm examining a dataset where everyone within the same household has the same ID, but different person numbers (PNUM).

 

They also have marital status pointers that point to PNUMs of their spouses.

 

I want to check if a persons spouse has some other condition.

 

What's the best way of going about this?


 

ballardw
Super User

I will say congratulations on thinking to check on such things.

 

However if your data looks like some of mine do not be surprised if one or more of the status point to someone in a different house, assuming the PNUM is unique across households and not assigned within household.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 625 views
  • 1 like
  • 3 in conversation