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

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 511 views
  • 0 likes
  • 2 in conversation