Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Missing Values

Status
Not open for further replies.

dblan

MIS
Jul 6, 2007
58
US
Is there a way to replace multiple missing values in a column with the previous non-misisng value?
Here is what a sample dataset would look like:

Code:
data have;
  input ProjectID $ Action $ UserID $;
  datalines;
Project1    Started    User1
Project1    Update1    User1
Project1    Update2    .
Project1    Update3    .
Project1    Update4    User1
Project1    Update5    User2
Project1    Update6    .
Project1    Update7    .
Project1    Update8    User1
;
run;

I would like to find a way to replace all the missing values with the non-missing value above it all the way down to the next non-missing value. The updated data would hopefully look like:

ProjectID Action UserID
Project1 Started User1
Project1 Update1 User1
Project1 Update2 User1
Project1 Update3 User1
Project1 Update4 User1
Project1 Update5 User2
Project1 Update6 User2
Project1 Update7 User2
Project1 Update8 User1

I've tried some things with the retain statement, but I'm not having any luck. Does anyone have any ideas on how I might accomplish this?

~Dave
 
data have2;
set have;
retain userid2;
if userid ne '' then userid2 = userid;
run;
 

Awesome, thanks. It looks like I was messing up in the if statement.
I had it backwards...."if UserID eq '' then UserID=UserID2;" and was only getting blanks.

thanks again,
~Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top