Help using Base SAS procedures

Output based on the value of next record

Reply
Frequent Contributor
Posts: 131

Output based on the value of next record

The decision to retain the current record is based on the value of a variable (Age) in the next record. If the next record has Age>30, then the current whole record should be kept. Is there any statement to deal with this?

Policy Location Year Age
142 12 1978 32
143 05 1980 31
144 17 1990 20

So in the output, the first record should be kept, and the second one deleted.
Valued Guide
Posts: 634

Re: Output based on the value of next record

Try this. Obviously you never want the last observation.
[pre]data ages;
input Policy Location Year Age;
datalines;
142 12 1978 32
143 05 1980 31
144 17 1990 20
145 05 1992 31
146 17 1995 39
run;

data usenext;
set ages(firstobs=2 keep=age rename=(age=nextage));
set ages;
if nextage>30;
run;
proc print data=usenext;
run;
[/pre]
Occasional Contributor
Posts: 13

Re: Output based on the value of next record

Very good idea. Great, ArtC.
Super User
Posts: 10,023

Re: Output based on the value of next record

Art.C 's code remind me the skill introduced by Peter.C


[pre]
data ages;
input Policy Location Year Age;
datalines;
142 12 1978 32
143 05 1980 31
144 17 1990 20
145 05 1992 31
146 17 1995 39
;
run;
data want(drop=_age);
merge ages ages(keep=age rename=(age=_age) firstobs=2);
if _age gt 30 ;
run;
[/pre]


Ksharp
Occasional Contributor
Posts: 13

Re: Output based on the value of next record

Marvelous ideas of you two.

Does Peter C. write any SAS books for me to learn these great ideas?
Super User
Posts: 10,023

Re: Output based on the value of next record

Posted in reply to Kevin_Graduate
Hi.
I called it Merge Skill .



Where are you ,Peter.C?
Someone want to talk to you.
Maybe you can introduce us some valueable documentations. :-)

Ksharp Message was edited by: Ksharp
Ask a Question
Discussion stats
  • 5 replies
  • 162 views
  • 0 likes
  • 4 in conversation