Help using Base SAS procedures

Moving value from one row to another

Reply
Super Contributor
Posts: 400

Moving value from one row to another

I have a simple question that I can't seem to figure out.

I have data like this

2000 1 2
. 1 3
. 1 4
2001 2 1
. 2 2
2002 3 1
. 3 2
. 3 3

How can I make the year show up for every row like this

2000 1 2
2000 1 3
2000 1 4
2001 2 1
2001 2 2
2002 3 1
2002 3 2
2002 3 3

Thank you
PROC Star
Posts: 7,492

Re: Moving value from one row to another

Posted in reply to jerry898969
Jerry,

The are a number of ways. The one I usually use is:
[pre]
data want (drop=hold);
set have;
retain hold;
if not(missing(year)) then hold=year;
year=ifn(missing(year),hold,year);
run;
[/pre]
HTH,
Art
Super Contributor
Posts: 400

Re: Moving value from one row to another

art,

That was it. Thank you so much
Super Contributor
Super Contributor
Posts: 365

Re: Moving value from one row to another

Posted in reply to jerry898969
Hello Jerry898969,

This is a solution:
[pre]
data i;
input y b c;
datalines;
2000 1 2
. 1 3
. 1 4
2001 2 1
. 2 2
2002 3 1
. 3 2
. 3 3
run;
data r;
retain y0;
set i;
if y NE . then y0=y;
else y=y0;
drop y0;
run;
[/pre]
Sincerely,
SPR
Super Contributor
Posts: 400

Re: Moving value from one row to another

SPR,

Thank you for your reply.

Jerry
Ask a Question
Discussion stats
  • 4 replies
  • 597 views
  • 0 likes
  • 3 in conversation