data step set statement end= option

Reply
Occasional Contributor
Posts: 5

data step set statement end= option

I am trying to create a variable that marks the last observation in a dataset by group. The SAS documentation leads me to believe this is the correct syntax, but it is not working. Only the last observation of the dataset is being set to 1, not the last observation of each by group. Why doesn't this work?? What am I missing here?

data long1 ;

  input famid year faminc ;

cards ;

1 96 40000

1 97 40500

1 98 41000

2 96 45000

2 97 45400

2 98 45800

3 96 75000

3 97 76000

3 98 77000

;

run;

proc sort data = long1; by famid; run;

data long2;

    set long1 end=last;

    by famid;

    end = last;

run;

Super User
Posts: 17,784

Re: data step set statement end= option

You're looking for by group and first/last processing.

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000761932.htm

data long1 ;

  input famid year faminc ;

cards ;

1 96 40000

1 97 40500

1 98 41000

2 96 45000

2 97 45400

2 98 45800

3 96 75000

3 97 76000

3 98 77000

;

run;

proc sort data = long1; by famid; run;

data long2;

set long1;

by famid;

first=first.famid;

last=last.famid;

run;

Ask a Question
Discussion stats
  • 1 reply
  • 236 views
  • 0 likes
  • 2 in conversation