BookmarkSubscribeRSS Feed
jkf91
Calcite | Level 5

Hi all,

I have a specific problem which I'm not sure how to solve. Suppose I have the following data called all.all:

Capture.JPG

I want to identify id's such as id 3. Eventually, I need to create a data subset that includes id's that:

1. do not have a change in household_size over years (e.g., id 2 had household_size change between 2004 and 2005.)

2. do nto have a gap year (e.g., id 1 is missing 2005)

Thanks,

Chris

3 REPLIES 3
art297
Opal | Level 21

Here is one way:

proc sql noprint;

  create table want1 as

    select *

      from have (where=(year in (2004, 2005)))

        group by id

          having min(household_size) eq

                 max(household_size) and

                 count(*) eq 2

  ;

  create table want2 as

    select *

      from have

        group by id

          having max(year)-min(year)+1 eq

                 count(*)

  ;

quit;

Tom
Super User Tom
Super User

data want ;

    yeargap = 0;

    sizechange=0;

   do until (last.id) ;

       set have ;

       by id ;

      yeargap = max(yeargap , year ne lag(year) and not first.id);

       sizechange = max(sizechange, size ne lag(size) and not first.id);

    end;

   keep id yeargap sizechange;

run;

Ksharp
Super User

How about:

data temp;
input id year household_size;
cards;
1 2004 2
1 2006 2
1 2007 2
1 2008 2
2 2003 3
2 2004 3
2 2005 2
3 2003 3
3 2004 3
3 2005 3
;
run;
proc sql noprint;
 create table want as
  select *
   from temp
    group by id
     having count(distinct household_size) eq 1 and range(year) eq count(year)-1;
quit;

Ksharp

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1263 views
  • 0 likes
  • 4 in conversation