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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 171 views
  • 0 likes
  • 2 in conversation