BookmarkSubscribeRSS Feed
bncoxuk
Obsidian | Level 7
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.
5 REPLIES 5
ArtC
Rhodochrosite | Level 12
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]
Kevin_Graduate
Calcite | Level 5
Very good idea. Great, ArtC.
Ksharp
Super User
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
Kevin_Graduate
Calcite | Level 5
Marvelous ideas of you two.

Does Peter C. write any SAS books for me to learn these great ideas?
Ksharp
Super User
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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