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 (December 2001, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 18 Dec 2001 11:43:45 -0500
Reply-To:     "Chakravarthy, Venky" <Venky.Chakravarthy@PFIZER.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Chakravarthy, Venky" <Venky.Chakravarthy@PFIZER.COM>
Subject:      Re: cumulative sums of a variable
Comments: To: "Philip A. Townsend" <townsend@AL.UMCES.EDU>
Content-Type: text/plain; charset="iso-8859-1"


You have already heard from the learned folks on this list. In addition to their solutions, here is one more. My solution takes advantage of the ability of the recent versions of SAS to process the _INFILE_ buffer as a variable. See if this suits your needs:

%macro readwrit ; %do i = 1 %to 3 ; %do j = 1 %to 25 ; filename in&i.&j. "c:\c_data\junk\lib1\f&i._&j..csv" ; filename out&i.&j. "c:\c_data\junk\lib2\f&i._&j..csv" ; data _null_ ; retain z ; infile in&i.&j. dlm = "," ; if _n_ > 1 then input x y @ ; input @ ; z + y ; if _n_ = 1 then _infile_ = _infile_ || ",Cumsum" ; else _infile_ = _infile_ || "," || put(z,3.) ; file out&i.&j. ; put _infile_ ; run ; %end ; %end ; %mend readwrit ;


#****************************************# # E-mail: # # # # Phone: (734) 622-1963 # #****************************************#

-----Original Message----- From: Philip A. Townsend [mailto:townsend@AL.UMCES.EDU] Sent: Tuesday, December 18, 2001 8:48 AM To: SAS-L@LISTSERV.UGA.EDU Subject: cumulative sums of a variable


I am a low/mid-grade sas user and have a couple of help questions:

(1) I have a series of 75 files with data that exist in 2 levels. All files have a "f" as the prefix, then have a first level of 3 values, that is f1, f12, and f3 and then 25 levels in the second level, i.e. f1_1 through f1_25 and f2_1 through f2_25, and so on. I want to automate reading these csv files into sas data sets that have the same name levels. I know I can do this with do loops, but I am having trouble with the syntax for naming these and assigning them the appropriate names.

This is the harder one for me: (2) Once I have these 75 data sets read in (or I can read them in one at a time), I want to do the following process to each. Each data set has two variables, VALUE and COUNT (originally output from a GIS). I sort the data by VALUE. I want to create a new variable with cumulative sum of COUNT. That is if my original data are as such:

obs VALUE COUNT 1 1 13 2 4 356 3 5 231 4 9 18 5 11 1002 6 12 88

I want an output file created that looks as such:

Obs VALUE COUNT CUMSUM 1 1 13 13 2 4 356 369 3 5 231 600 4 9 18 618 5 11 1002 1620 6 12 88 1708

These files will then be output back to CSV files to be read back into to GIS.

So I want to automate reading in the 75 files with a 2-level naming convention, determine the cumulative sum of count (with the data sorted by value) and then write back out to new data sets that follow similar naming conventions.

Cam anyone provide some help?

Thanks, Phil Townsend


Phil Townsend Assistant Professor University of Maryland Center for Environmental Science Appalachian Laboratory 301 Braddock Road Frostburg, MD 21532-2307 USA

phone: 301.689.7124 fax: 301.689.7200 email:

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