Hi All,
I am trying to fill the below cells with repetitive value. Can someone help me please
My Table (table name is have)
State Name
NY Joy
Thomas
Mike
TX Albert
James
IL Corey
Output Table (Table name is want):
State Name STATE2
NY Joy NY
Thomas NY
Mike NY
TX Albert TX
James TX
IL Corey IL
Here is one way:
data want; set have; retain state2; if not missing(state) then state2=state; run;
Art, CEO, AnalystFinder.com
Run the code on your data. It does what I think you requested.
Art, CEO, AnalystFinder.com
@mlogan wrote:
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.
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.