BookmarkSubscribeRSS Feed
Mousemo1
Calcite | Level 5

I have this data set:

IDHOH
9031
AB40
26A0
E521
53D0
400
7B60
E8D1
A800
AA60
63A1
3DB0
A570
D270
4500
F4D0
0A20
37F1
E521
2821
2681

 

The IDs are individuals and HOH = 1 is the head of household for the next records with HOH = 0.  Then the next HOH = 1 start the next household group.  I need to group those like this:

 

IDHOHHousehold
9031903
AB40903
26A0903
E521E52
53D0E52
400E52
7B60E52
E8D1E8D
A800E8D
AA60E8D
63A163A
3DB063A
A57063A
D27063A
450063A
F4D063A
0A2063A
37F137F
E521E52
2821282
2681268

 

So create groups where groups do not exist.  The file comes sorted so the first HOH = 1 and HOHs = 0 are in the same household.

 

Thanks

1 REPLY 1
PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

data want;
    retain household;
    set have;
    if hoh=1 then household=id;
run;
--
Paige Miller

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
  • 1 reply
  • 607 views
  • 0 likes
  • 2 in conversation