Help using Base SAS procedures

What is happening in this do until construct?

Reply
Super Contributor
Posts: 338

What is happening in this do until construct?

Hi SAS Forum,

Could any one please help me to understand what is happening in this do until code which was posted recently (I reproduced below). 

consecutive observations only

jkf91 Jan 14, 2012 4:23 PM

Data have;

input Panelist  Year;

cards;

1 2003

1 2004

1 2005

1 2006

1 2008

1 2009

2 2003

2 2004

2 2005

2 2007

2 2008

2 2009

3 2003

3 2004

;

run;

jkf91’s question:

Wanted to remove the years that are not consecutive for at least three years so that he would get the below records chosen.

1

2003

1

2004

1

2005

1

2006

2

2003

2

2004

2

2005

2

2007

2

2008

2

2009

Note that panelist 3 was entirely removed since it only has 2 (<3) consecutive years.

Howles has provided below Double DoW code which does the job.

/* pre-processing to create an appropriate BY variable */

data grouped ;

set have ;

by panelist ;

groupnum + ( first.panelist OR ( dif(year) GT 1 ) ) ;

run ;

data want ;

do many = 1 by 1 until (last.groupnum) ;

   set grouped ;

   by groupnum ;

   end ;

do nn = 1 to many ;

   set grouped ;

/*There is no by statement here but still the code works*/

   if many GE 3 then output ;

   end ;

run ;

My question is this:

I can understand only some parts of this code.

I can understand Preprocessing step.

In do until part, there are 2 loops.

Each “groupnum” goes through the first loop. But what is happening there?

In the second loop, I can only understand this:

“if the variable called “many” is GE 3, then a output file is produced”.

But There is no by statement there but still the code works.

Could anyone please elaborate what is happening in this do until construct?

Thank you

Mirisage

Ask a Question
Discussion stats
  • 0 replies
  • 112 views
  • 0 likes
  • 1 in conversation