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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.