Building models with SAS Enterprise Miner, SAS Factory Miner, SAS Visual Data Mining and Machine Learning or just with programming

Carry forward the same value to end

Reply
Contributor
Posts: 26

Carry forward the same value to end

Hi I've data like following.
custnbr mob bal
A 0 1
A 1 1
A 2 1
A 3 1
A 4 0
A 5 0
A 6 0
A 7 1
A 8 0
B 0 0
B 1 0
B 2 0
B 3 0
B 4 1
B 5 1
B 6 1
B 7 0

i need result like following.

A 0 1
A 1 1
A 2 1
A 3 1
A 4 1
A 5 1
A 6 1
A 7 1
A 8 1
B 0 0
B 1 0
B 2 0
B 3 0
B 4 1
B 5 1
B 6 1
B 7 1

basically the value when the record starts Bal = 1 then the same value should carry till end for the same customer.

Thanks in advance.
Super Contributor
Super Contributor
Posts: 3,174

Re: Carry forward the same value to end

In a DATA step and using your SORTed file, you can use a temporary SAS variable (look up the RETAIN stmt) to test-for and capture the IF FIRST.CUSTNBR condition, and then assign the variable BAL to whatever is desired.

Scott Barry
SBBWorks, Inc.

DATA Step Processing
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm

BY-Group Processing in the DATA Step (FIRST. is discussed here):
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001283274.htm

Understanding the SAS® DATA Step and the Program Data Vector
Steven First, Systems Seminar Consultants, Madison, WI
http://support.sas.com/resources/papers/proceedings09/136-2009.pdf
Ask a Question
Discussion stats
  • 1 reply
  • 172 views
  • 0 likes
  • 2 in conversation