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

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 600 views
  • 1 like
  • 3 in conversation