From: "Dennis G. Fisher, Ph.D." on
Use an ARRAY statement and a DO loop.


Dennis G. Fisher, Ph.D.
Professor and Director
Center for Behavioral Research and Services
California State University, Long Beach
1090 Atlantic Avenue
Long Beach, CA 90813
tel: 562-495-2330 x121
fax: 562-983-1421

-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Tom
White
Sent: Saturday, October 17, 2009 12:46 PM
To: SAS-L(a)LISTSERV.UGA.EDU
Subject: Replace . by 0

Hello SAS-L, I have a data set with about 400 vars. Each var has its own
business name like price, discount, last12month, etc.So they are not like
var1 ... var400. Each one of these vars has missing values which represent
the value 0. How do I replace all these nulls by 0? Clearly, I don't wish to
type each variable and say, if price=. then price=0. Thank you. Tom

--
Be Yourself @ mail.com!
Choose From 200+ Email Addresses
Get a Free Account at www.mail.com!
From: Daniel Nordlund on
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On
> Behalf Of Tom White
> Sent: Saturday, October 17, 2009 12:46 PM
> To: SAS-L(a)LISTSERV.UGA.EDU
> Subject: Replace . by 0
>
> Hello SAS-L, I have a data set with about 400 vars. Each var
> has its own
> business name like price, discount, last12month, etc.So they
> are not like
> var1 ... var400. Each one of these vars has missing values which
> represent the value 0. How do I replace all these nulls by 0?
> Clearly, I
> don't wish to type each variable and say, if price=. then
> price=0. Thank
> you. Tom
>

Here is one option:

data want;
set have;
array temp[*] _numeric_ ;
do _n_ = 1 to dim(temp);
if missing(temp[_n_]) then temp[_n_] = 0;
end;
run;

Hope this is helpful,

Dan

Daniel Nordlund
Bothell, WA USA
From: Mike Zdeb on
hi ... a tweak on Dan's program
use the SUM function and add zero to each value
since functions ignore missing values, missing + 0 = 0

data have;
input id : $1. a b c d e;
datalines;
A 1 . 2 . 5
B 1 2 3 4 5
C . . . . .
;
run;

data want;
set have;
array temp[*] _numeric_ ;
do _n_ = 1 to dim(temp);
temp(_n_) = sum(temp(_n_),0);
end;
run;

data set want ...

Obs id a b c d e
1 A 1 0 2 0 5
2 B 1 2 3 4 5
3 C 0 0 0 0 0




--
Mike Zdeb
U(a)Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475

>> -----Original Message-----
>> From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On
>> Behalf Of Tom White
>> Sent: Saturday, October 17, 2009 12:46 PM
>> To: SAS-L(a)LISTSERV.UGA.EDU
>> Subject: Replace . by 0
>>
>> Hello SAS-L, I have a data set with about 400 vars. Each var
>> has its own
>> business name like price, discount, last12month, etc.So they
>> are not like
>> var1 ... var400. Each one of these vars has missing values which
>> represent the value 0. How do I replace all these nulls by 0?
>> Clearly, I
>> don't wish to type each variable and say, if price=. then
>> price=0. Thank
>> you. Tom
>>
>
> Here is one option:
>
> data want;
> set have;
> array temp[*] _numeric_ ;
> do _n_ = 1 to dim(temp);
> if missing(temp[_n_]) then temp[_n_] = 0;
> end;
> run;
>
> Hope this is helpful,
>
> Dan
>
> Daniel Nordlund
> Bothell, WA USA
>
From: "Data _null_;" on
IF you have SAS/STAT software you can use STDIZE. The default method
complains with all kinds of warning but I don't understand why when
REPONLY is specified. Perhaps a bird knows why. Anyway here is the
code.

data have;
input id : $1. a b c d e;
datalines;
A 1 . 2 . 5
B 1 2 3 4 5
C . . . . .
;
run;

proc stdize out=need reponly missing=0 method=mean;
run;
proc print;
run;


On 10/17/09, Mike Zdeb <msz03(a)albany.edu> wrote:
> hi ... a tweak on Dan's program
> use the SUM function and add zero to each value
> since functions ignore missing values, missing + 0 = 0
>
> data have;
> input id : $1. a b c d e;
> datalines;
> A 1 . 2 . 5
> B 1 2 3 4 5
> C . . . . .
> ;
> run;
>
> data want;
> set have;
> array temp[*] _numeric_ ;
> do _n_ = 1 to dim(temp);
> temp(_n_) = sum(temp(_n_),0);
> end;
> run;
>
> data set want ...
>
> Obs id a b c d e
> 1 A 1 0 2 0 5
> 2 B 1 2 3 4 5
> 3 C 0 0 0 0 0
>
>
>
>
> --
> Mike Zdeb
> U(a)Albany School of Public Health
> One University Place
> Rensselaer, New York 12144-3456
> P/518-402-6479 F/630-604-1475
>
> >> -----Original Message-----
> >> From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On
> >> Behalf Of Tom White
> >> Sent: Saturday, October 17, 2009 12:46 PM
> >> To: SAS-L(a)LISTSERV.UGA.EDU
> >> Subject: Replace . by 0
> >>
> >> Hello SAS-L, I have a data set with about 400 vars. Each var
> >> has its own
> >> business name like price, discount, last12month, etc.So they
> >> are not like
> >> var1 ... var400. Each one of these vars has missing values which
> >> represent the value 0. How do I replace all these nulls by 0?
> >> Clearly, I
> >> don't wish to type each variable and say, if price=. then
> >> price=0. Thank
> >> you. Tom
> >>
> >
> > Here is one option:
> >
> > data want;
> > set have;
> > array temp[*] _numeric_ ;
> > do _n_ = 1 to dim(temp);
> > if missing(temp[_n_]) then temp[_n_] = 0;
> > end;
> > run;
> >
> > Hope this is helpful,
> >
> > Dan
> >
> > Daniel Nordlund
> > Bothell, WA USA
> >
>