Date: Tue, 31 Mar 2009 11:40:48 -0700
Reply-To: Dale McLerran <stringplayer_2@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Dale McLerran <stringplayer_2@YAHOO.COM>
Subject: Re: test for variable: Numeric or Character
Content-Type: text/plain; charset=iso-8859-1
--- On Tue, 3/31/09, papu <prachar@GMAIL.COM> wrote:
> From: papu <prachar@GMAIL.COM>
> Subject: test for variable: Numeric or Character
> To: SAS-L@LISTSERV.UGA.EDU
> Date: Tuesday, March 31, 2009, 11:20 AM
> Hi All,
>
> In a sas datastep I want to test if a variable is numeric
> or character
> and depending on that I want to assign a value. I have a
> macro that
> can access every variable in a dataset and I can access
> it.
>
> For eg. the following datastep is for missing value
> replacement.
>
> data dat2;
> set dat1;
>
> if &&var&i. = numeric and
> &&var&i.= . then &&var&i. = -99990;
> if &&var&i. =
> character and &&var&i.= ' ' then
> &&var&i. =
> '-99990';
>
> run;
>
> How can I test if &&var&i. =
> character and if &&var&i. =
> numeric?
>
> thanks
> Papu.
>
Papu,
Before addressing your question as you have posed it, let me
ask if all numeric variables would be handled similarly and
if all character variables would be handled similarly. That
is, can you use code like the following:
data dat2;
set dat1;
array _numvars_ {*} _numeric_;
array _charvars_ {*} _character_;
do i=1 to dim(_numvars_};
if missing(_numvars_{i}) then _numvars_{i}=-99990;
end;
do i=1 to dim(_charvars_};
if missing(_charvars_{i}) then _charvars_{i}='-99990';
end;
run;
In this code, every numeric missing is assigned the value -99990
and every character missing is assigned the value '-99990'. Is
there anything wrong with this code?
Dale
---------------------------------------
Dale McLerran
Fred Hutchinson Cancer Research Center
mailto: dmclerra@NO_SPAMfhcrc.org
Ph: (206) 667-2926
Fax: (206) 667-5977
---------------------------------------