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?
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?
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.
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.
Ready to level-up your skills? Choose your own adventure.