| Date: | Tue, 5 Dec 2006 07:30:50 -0500 |
| Reply-To: | Jake Bee <johbee@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Jake Bee <johbee@GMAIL.COM> |
| Subject: | Re: Arithmetic Operations |
|
| In-Reply-To: | <1165318892.548716.276590@f1g2000cwa.googlegroups.com> |
| Content-Type: | text/plain; charset=ISO-8859-1; format=flowed |
Yes, your missing will be if disp3_1=. then disp3_1=0
or you could use if nmiss(disp3_1) then disp3_1=0;
Two examples are below, but the second is easier -- with the sum (of ...)
you don't have to worry about the missing values.
*---- example 1 ---------------------------------------------------*;
data a;
disp3_1=.; disp3_2=1; disp4_1=2; disp4_2=5; output;
disp3_1=1; disp3_2=1; disp4_1=3; disp4_2=6; output;
disp3_1=.; disp3_2=.; disp4_1=4; disp4_2=7; output;
disp3_1=.; disp3_2=1; disp4_1=5; disp4_2=.; output;
disp3_1=5; disp3_2=4; disp4_1=3; disp4_2=1; output;
run;
data arth(drop=i j);
set a;
x=0;
array disp3_{*} disp3_1 disp3_2;
array disp4_{*} disp4_1 disp4_2;
do i=1 to dim(disp3_);
if nmiss(disp3_{i}) then disp3_{i}=0;
x=disp3_{i} + x;
end;
do j=1 to dim(disp4_);
if nmiss(disp4_{j}) then disp4_{j}=0;
x=disp4_{j} + x;
end;
run;
proc print data=arth;
run;
*--- example 2 --------------------------*;
data sumit;
set a;
array values[*] disp3_1 disp3_2 disp4_1 disp4_2;
tally=sum(of values[*]);
run;
proc print data=sumit;
run;
On 12/5/06, jshansen <selchauhansen@gmail.com> wrote:
>
> On 5 Dec., 12:15, "Priya" <priyawor...@yahoo.com> wrote:
> > Hi Every1,
> >
> > I have a small difficulty in writing the assignment statements in an
> > efficient manner.
> >
> > For eg, in a dataset I have variables like DISP3_1 DISP3_2 DISP4_1
> > DISP4_3, etc
> >
> > If have to do convert all missing values for DISP eq to zero, how will
> > I do it without using do loop and without having to manually write all
> > assignment statements like
> >
> > if DISP3_1 = "." then DISP3_1 = 0;
> > if DISP3_2 = "." then DISP3_2 = 0;
> > and so on ...
> >
> > Writing a do loop may not be a good of doing this if I do not want to
> > track all the display variables created in the dataset which may be
> > huge.
> >
> > I tried doing something like:
> > if DISP: = "." then DISP: = 0;
> >
> > but it did not work.
> >
> > Kindly suggest a way to handle it in a smart manner.(This may hold true
> > for any arithmetic operation.)
> >
> > Also, suggest if we can convert all missing values for all the
> > variables in a dataset to zero in one go.
> >
> > Thanks,
> > Priya
>
> Priya !
>
> A missing value is NOT enclosed in quotes !!
> Nor are any numeric values.
>
> Mind You than you should NOT do this, unless you have a very very good
> reason to do it.
>
> data a;
> set sashelp.class;
> array numbers _numeric_;
> do over numbers;
> numbers=sum(numbers,0);
> end;
> run;
>
> Jan Selchau-Hansen
>
|