To replace the value from the first row to all remaining rows for the same user_id

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

To replace the value from the first row to all remaining rows for the same user_id

I have one of unique problem facing; I have the following data set

27-03-2015 12-59-08.png

The problem is the dates in the start date are inconsistent apart from the first row startdate(which is correct) for each user_id, So now the start date as to be replaced from the first row of the each unique user_id to the remaining rows of the same user_id

For example; for User_id '456225' the correct start date is in the first row ( 01.07.2012) and all those dates apart from 01.07.2012 are wrong, Hence those wrong dates as to be replaced by the 01.072012 which is present in the first row for user_id. And this as to be done for all the uniue user_id which rins upto 90,000.00.

thanks

Pra


Accepted Solutions
Solution
‎03-27-2015 04:18 AM
Occasional Contributor
Posts: 19

Re: To replace the value from the first row to all remaining rows for the same user_id

you can use the retain statement.

like this.

data want;

set have;

retain new_date;

by user_id start_date notsorted;

if first.user_id then new_date=start_date; else start_date=new_date;

drop new_date;run;

View solution in original post


All Replies
Solution
‎03-27-2015 04:18 AM
Occasional Contributor
Posts: 19

Re: To replace the value from the first row to all remaining rows for the same user_id

you can use the retain statement.

like this.

data want;

set have;

retain new_date;

by user_id start_date notsorted;

if first.user_id then new_date=start_date; else start_date=new_date;

drop new_date;run;

Contributor
Posts: 20

Re: To replace the value from the first row to all remaining rows for the same user_id

Posted in reply to viveklanka

Hi Vivek,

This is working, However Suppose if the correct startdate was in the second or third row of the user id then how to proceed?

Thanks

Super User
Posts: 19,780

Re: To replace the value from the first row to all remaining rows for the same user_id

How do you identify what is a 'correct' start date?

SInce you have an answer to your original question you should mark this question answered and ask a new one.

Occasional Contributor
Posts: 19

Re: To replace the value from the first row to all remaining rows for the same user_id

In that case you

1. have to have a sequence.

2. then sort according to that

3. and follow the above procedure.

I agree with you can ask a new question by marking this answered.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 251 views
  • 1 like
  • 3 in conversation