08-27-2017 05:07 PM
I am trying to fill the below cells with repetitive value. Can someone help me please
My Table (table name is have)
Output Table (Table name is want):
State Name STATE2
NY Joy NY
TX Albert TX
IL Corey IL
08-27-2017 07:40 PM
08-27-2017 08:05 PM
Hi art297, Your code just copy the column STATE to STATE2.
No it doesn't.
The code is:
data want; set have; retain state2; if not missing(state) then state2=state; run;
RETAIN holds the value until it is changed explicitly.
The assignment of State to STATE2 only occurs when there is a new value of STATE. It returns exactly your desired stated output using the simplest methods.
If it isn't doing what you want, you need to provide more details.
08-27-2017 05:33 PM
This should do the trick
data have; infile datalines dlm="," missover truncover; length state $2 name $6; input state $ name $; datalines; NY,Joy ,Thomas ,Mike TX,Albert ,James IL,Corey ; run; data want(drop=holdstate); length state2 $2; set have; if _n_=1 then do; holdstate=state; state2=state; end; else do; if state="" then state2=holdstate; else do; holdstate=state; state2=state; end; end; retain holdstate; run;