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 (March 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 18 Mar 2010 14:20:29 -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: It takes so long. Should I stop it?
In-Reply-To:   <262853.2347.qm@web114408.mail.gq1.yahoo.com>
Content-Type:   text/plain; charset=iso-8859-1

--- On Thu, 3/18/10, Karen L <hl2493@YAHOO.COM> wrote:

> From: Karen L <hl2493@YAHOO.COM> > Subject: It takes so long. Should I stop it? > To: SAS-L@LISTSERV.UGA.EDU > Date: Thursday, March 18, 2010, 1:53 PM > Hi guys, > how are you doing? It's wonderful weather here in NYC! > I have a very simple question here. > > > dataset kr2 has 4,769,280 rows. (4,769,280*5 matrix) > > I've been trying to perform this: > > data kr1; set kr2; > do i=1 to 103680; > if 46*i-45<=obs<=46*i then group1=i; > end; > run; > > > It has been more than 40 mins since I've run it. > > I know, it's a pretty large dataset; but, I don't know why > it takes so long. > Not sure whether I should stop it or continue to wait for > its result. > > Do you have any good idea? > > Thanks, > Karen >

Karen,

Are you trying to assign the first group of 45 observations to group1=1, then next group of 45 observations to group1=2, etc.? It would appear so. However, I doubt if your code will do that because I don't see any place where the variable OBS is assigned. You probably want the variable _N_ instead of OBS.

However, even if you were to replace OBS with _N_, this would not be good code. You are looping through an index with 103680 values for every record you read in. But you don't need to do that. Instead, I would write this as

data kr1; set kr2; if mod(_n_,45)=1 then group1+1; run;

The MOD function returns the remainder that is obtained when the first argument is divided by the second argument. At records 1, 46, 91, ... the remainder is 1. Each time the remainder is 1, we increment the variable group1 by 1. This code uses what is referred to in the SAS documentation as a sum statement. A sum statement is one which could be written as

X + A;

where X is a variable to which the value A is added. When a sum statement is employed, the variable X is automatically retained. Moreover, if X has not previously been assigned (is missing), then we have

X + A = A

In your case, the variable X is group1 and we want to add the value 1 whenever the condition is true. The first time the condition is true, we end up assigning the value 1 to group1.

HTH,

Dale

--------------------------------------- Dale McLerran Fred Hutchinson Cancer Research Center mailto: dmclerra@NO_SPAMfhcrc.org Ph: (206) 667-2926 Fax: (206) 667-5977 ---------------------------------------


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