Date: Tue, 18 Nov 2008 16:05:06 -0800
Reply-To: karma <dorjetarap@GOOGLEMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: karma <dorjetarap@GOOGLEMAIL.COM>
Organization: http://groups.google.com
Subject: Re: data manipulation
Content-Type: text/plain; charset=ISO-8859-1
On Nov 18, 11:10 pm, hd <heen...@gmail.com> wrote:
> Hello,
>
> My question is if I have a data set that looks like this
>
> Var Set
> a 1
> b
> c
> d 2
> e
> f
> g
> h 3
> i
>
> and I would like it to like this
>
> Var Set
> a 1
> b 1
> c 1
> d 2
> e 2
> f 2
> g 2
> h 3
> i 3
>
> In other words I want to just duplicate the entries until I reach an
> entry in the Set column and then want to duplicate that. I am not sure
> how I can do this, any help will be greatly appreciated.
>
> Thank you!
Hi,
Here I assign the non-missing value of set to a temporary variable and
then use retain - which tells SAS not to reinitialize the variable -
and then assign the variable back to set for the missing values.
data have;
infile cards missover;
input var$ set;
cards;
a 1
b
c
d 2
e
f
g
h 3
i
;run;
proc print;run;
data want(drop=_:);
set have;
retain _x;
if ^missing(set) then _x = set;
else set = _x;
run;
proc print;run;
Alternatively you can take advantage of the drop executing before the
rename dataset option and avoid the second assignments:
data want(drop=set rename=(_x=set));
set have;
retain _x;
if ^missing(set) then _x = set;
run;
proc print;run;