LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (September 1998, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 7 Sep 1998 21:35:24 -0400
Reply-To:     S David Riba <dave@JADETEK.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         S David Riba <dave@JADETEK.COM>
Subject:      Re: I'm an idiot, please help! How to create cummulative variable.
Comments: To: Edward Kohl <erkohl@TALKNET.DE>
Content-Type: text/plain; charset="iso-8859-1"

Not at all. The answer is obvious, but not intuitive.

You have several different options in SAS. The simplest is:

ARCUM + ARMEAN ;

You could also have used a RETAIN statement:

RETAIN ARCUM 0 ;

ARCUM = ARCUM + ARMEAN ;

Both work. I find the first example significantly less typing. For the reasons why these work and your initial example did not, you have to understand the default SAS processing that sets variables equal to a missing value with each iteration of the data step. Over the years there have been several extremely well presented posts on SAS-L on the topic, so I'm not going to try to repeat them. Suffice it to say, with each pass of the data step you were resetting ARCUM to missing.

Hope the above helps.

---------------------------------------------------------------------------- S. David Riba INTERNET: dave@JADETEK.COM JADE Tech, Inc. http://www.jadetek.com P O Box 4517 Clearwater, FL 33758 VOICE: (727) 726-6099 A SAS Institute Quality Partner

SAS. It's not just an attitude

-----Original Message----- From: Edward Kohl <erkohl@TALKNET.DE> Newsgroups: bit.listserv.sas-l To: SAS-L@UGA.CC.UGA.EDU <SAS-L@UGA.CC.UGA.EDU> Date: Monday, September 07, 1998 9:25 PM Subject: I'm an idiot, please help! How to create cummulative variable.

>O.K. I'm a beginner, but that's still no excuse for not >being able to do the most basic SAS operation!! Please >flame me when you reply. > >I have a varaible, ARMEAN, with 201 observations and all I >want to do is create a new variable, ARCUM, whose value is >the sum of all previous ARMEANS values. In other words, I >want a cumulative value of all previous ARMEANS for each >iteration. > >So it would look something like this: > >ARMEAN ARCUM >1 1 >2 3 >3 6 >4 10 > >Sounds easy enough, right? Well, I tried doing this, > >ARCUM = ARMEAN + lag(ARCUM) > >but all I got was a column of missing values. I've also >tried the 'retain' command to set an intitial value for >ARCUM but that didn't work either, or I didn't use it >correctly. I've tried other things as well but I won't >repeat them here because you'll just laugh at me. > >I know I'm missing something completely obvious, but I'd >rather embarrass myself on a newsgroup than risk being >dragged away to a mental institution? Thanks. > >Edward


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