Date: Wed, 3 Oct 2001 08:59:40 -0400
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: John Hixon <125241N@KNOTES.KODAK.COM>
Subject: Re: SAS/IML manipulating subscripts
Content-type: text/plain; charset=us-ascii
From: John Hixon
>does anyone know how within SAS/IML I can delete observations.
>For example within a data set "dat" containing the variable v1, v2, v3, I
>would like to delete the observations corresponding to the values of v3 equal to 3.
>Thanks for your help.
I'm just catching up with the list in digest mode.
Dale McLerran has already supplied one method. I invariably learn something from
Dale's posts, whether it deals with Statistical Theory, or SAS pgming.
We in SAS-L are lucky that Dale takes the time to share his extensive knowledge.
Here is another approach that uses the IML "loc" function. In this example
we are testing to see if a matrix element in Column 3 exactly equals 3,
then deleting the entire corresponding row. This works if we know for certain
that the values are integers (ie 3=3). In "real life" we would want to use
and epsilon neigborhood to define what "v3=3" really means, but, that would
clutter up this example. My intent is to simply show how to use the loc function.
* create dummy data;
data dat (drop=n i);
do n=1 to 25;
do i=1 to 3;
if i=3 then output;
options ps=90 nonumber nodate;
* form new Matrix SubSet_X that deletes all rows where v3=3;
read all into X; * v1|v2|v3;
LocV3_NotEq3=loc(X[,3]^=3); * form locations of X where Col3 .ne. 3;
LocV3_Eq3=loc(X[,3]=3); * form locations of X where Col3 .eq. 3;
SubSet_X=X[LocV3_NotEq3,]; * form SubSet_X = All rows where Col3 .ne. 3;
Eastman Kodak Co
Rochester, NY, USA;