LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2001, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 3 Oct 2001 08:59:40 -0400
Reply-To:     125241N@KNOTES.KODAK.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         John Hixon <125241N@KNOTES.KODAK.COM>
Subject:      Re: SAS/IML manipulating subscripts
Comments: To: Philippe.Guiblin@ONS.GOV.UK
Content-type: text/plain; charset=us-ascii

From: John Hixon

/* Philippe asked:

>Dear all,

>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); array v{3}; do n=1 to 25; do i=1 to 3; v(i)=ceil(3+3*rannor(678)); if i=3 then output; end; end; run; proc print; run; title; options ps=90 nonumber nodate; * form new Matrix SubSet_X that deletes all rows where v3=3; proc iml; reset autoname; use dat; read all into X; * v1|v2|v3; print X; 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; print LocV3_Eq3; SubSet_X=X[LocV3_NotEq3,]; * form SubSet_X = All rows where Col3 .ne. 3; print SubSet_X; quit;

*

HTH

John Hixon Eastman Kodak Co Rochester, NY, USA;


Back to: Top of message | Previous page | Main SAS-L page