## Help on data step -

Occasional Contributor
Posts: 19

# Help on data step -

Hi All,

I need to have some solution for the below situtuion which i have come acorss recently. I have to find the latest reporting division value based on the month for each employee and it should be updated all the other data in the same column.

For Example. The latest reporting division for the employee 85766 is 'C' and the value should be updated for the rest of months. which means all the reporting division value is 'C' for 85776 employee.

Please see the dataset below.

Emp_NO REPORTING_DIVISION DIVISIONAL_CODE MONTH

85776 B B 201201

85776 B B 201202

85776 B B 201203

85776 B B 201204

85776 B B 201205

85776 B B 201206

85776 B B 201207

85776 B B 201208

85776 B B 201209

85776 B B 201210

85776 B B 201211

85776 B B 201212

85776 B B 201301

85776 B B 201302

85776 B B 201303

85776 B B 201304

85776 B B 201305

85776 B B 201306

85776 B B 201307

85776 B B 201308

85776 B B 201309

85776 B B 201310

85776 B B 201311

85776 B B 201312

85776 B B 201401

85776 B B 201402

85776 B B 201403

85776 B B 201404

85776 B B 201405

85776 B B 201406

85776 C C 201407

85776 C C 201408

85776 C C 201409

86322 B B 201201

86322 B B 201202

86322 B B 201203

86322 B B 201204

86322 B B 201205

86322 B B 201206

86322 B B 201207

86322 B B 201208

86322 B B 201209

86322 B B 201210

86322 B B 201211

86322 B B 201212

86322 B B 201301

86322 B B 201302

86322 B B 201303

86322 B B 201304

86322 C C 201407

86322 C C 201408

86322 C C 201409

Thanks in advance.

Kannan.

Super User
Posts: 13,358

## Re: Help on data step -

Posted in reply to KannanBaskar

Something like this might work:

Proc sort data=have; By Emp_no Month;run;

data temp;

set have;

by Emp_no;

if last.Emp_no;

run;

data want;

update have temp (drop= month divisional_code); /* if you want to update the divisional code as well do not include it in the drop */

by emp_no;

run;

Super User
Posts: 10,698

## Re: Help on data step -

Posted in reply to KannanBaskar

You didn't post your output yet.

Assuming the data has already been sorted.

```data have;
input Emp_NO REPORTING_DIVISION \$ DIVISIONAL_CODE \$ MONTH     ;
cards;
85776 B B 201201
85776 B B 201202
85776 B B 201203
85776 B B 201204
85776 B B 201205
85776 B B 201206
85776 B B 201207
85776 B B 201208
85776 B B 201209
85776 B B 201210
85776 B B 201211
85776 B B 201212
85776 B B 201301
85776 B B 201302
85776 B B 201303
85776 B B 201304
85776 B B 201305
85776 B B 201306
85776 B B 201307
85776 B B 201308
85776 B B 201309
85776 B B 201310
85776 B B 201311
85776 B B 201312
85776 B B 201401
85776 B B 201402
85776 B B 201403
85776 B B 201404
85776 B B 201405
85776 B B 201406
85776 C C 201407
85776 C C 201408
85776 C C 201409
86322 B B 201201
86322 B B 201202
86322 B B 201203
86322 B B 201204
86322 B B 201205
86322 B B 201206
86322 B B 201207
86322 B B 201208
86322 B B 201209
86322 B B 201210
86322 B B 201211
86322 B B 201212
86322 B B 201301
86322 B B 201302
86322 B B 201303
86322 B B 201304
86322 C C 201407
86322 C C 201408
86322 C C 201409
;
run;
data want;
do until(last.Emp_NO);
set have;
by Emp_NO;
end;
_X=REPORTING_DIVISION;
do until(last.Emp_NO);
set have;
by Emp_NO;
REPORTING_DIVISION=_X;     output;
end;
drop _X;
run;

```

Xia Keshan

Discussion stats
• 2 replies
• 530 views
• 0 likes
• 3 in conversation