BookmarkSubscribeRSS Feed
Augusto
Obsidian | Level 7

i need to replicate the value of the previos line (_n_ - 1) to line (_n_), could anyone code it.

 

ex.

 

data have ;
input n field $;
cards ;
1 y12
2 .
3 .
4 b98
5 .
6 .
7 .
;
run ;

 

data want;

set have;

n field
1 y12
2 y12
3 h12
4 b98
5 b98
6 b98
7 b98

run;

 

please, consider that this table (have) cannot be ordered

 

Thanks

3 REPLIES 3
ndp
Quartz | Level 8 ndp
Quartz | Level 8

Simple retain statement would work.

data want;
	set have;
	retain field1;
	if not missing(field) then field1=field;
run;

 

 

dsbihill
Obsidian | Level 7


data want;
    set have;

    retain prevField;
    if field ne "" then prevField = field;
    if field = "" then field = prevField;

run;

Steelers_In_DC
Barite | Level 11

Here is a solution:

 

data have;
input n field$;
cards ;
1 y12
2 .
3 .
4 b98
5 .
6 .
7 .
;

data want;
set have;
retain field2;
if not missing(field) then field2 = field;
if missing(field) then field = field2;
drop field2;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 964 views
  • 0 likes
  • 4 in conversation