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 (May 1999, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 13 May 1999 09:06:15 -0700
Reply-To:     "Berryhill, Timothy" <TWB2@PGE.COM>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         "Berryhill, Timothy" <TWB2@PGE.COM>
Subject:      Re: how do i do this
Comments: To: "frank.mwaniki@PHARMA.NOVARTIS.COM"
          <frank.mwaniki@PHARMA.NOVARTIS.COM>
Content-Type: text/plain

Frank, It looks like the dates for the 12 AMT&n variables are constant during a run (change each time you run the program, but do not change from observation to observation). Suppose you capture the first value (the date of the first day of that month) in a macro variable. In the datastep which should sum the relevant values, define an array containing all 12 AMT variables. Do not get tricky about the array index--let it run from 1 to 12. Next, in the summing step, create STARTDT and ENDDT as STARTDT=INPUT(START,MMMYY5.); This reads your style of month and year, and returns the date of the first day of the month. OK, now you have the dates for START and END, and you have the date of AMT&1. Use the INTCK function to convert STARTDT and ENDDT to offsets into your array: STARTPTR=1+INTCK(MONTH,&AMT1DT,STARTDT); It is tempting here to define the array as 0:11 to avoid that 1+, but I would default the array to 1:12. Anyway, now you can step through the array and sum up the months you want: SUM=0; DO PTR=STARTPTR TO ENDPTR; SUM=SUM(SUM,MYARRAY(PTR)); END;

Of course, you have to wrap this in something to protect against out of range dates: STARTPTR=MAX(1,STARTPTR); and ENDPTR=MIN(12,ENDPTR); IF STARTPTR GT 12 OR ENDPTR LT 1 THEN SUM=0; ELSE /* step through the array as shown above */

Tim Berryhill - Contract Programmer and General Wizard TWB2@PGE.COM or http://www.aartwolf.com/twb.html Frequently at Pacific Gas & Electric Co., San Francisco The correlation coefficient between their views and my postings is slightly less than 0

> ---------- > From: Frank Mwaniki[SMTP:frank.mwaniki@PHARMA.NOVARTIS.COM] > Reply To: frank.mwaniki@PHARMA.NOVARTIS.COM > Sent: Thursday, May 13, 1999 8:25 AM > To: SAS-L@UGA.CC.UGA.EDU > Subject: how do i do this > > Hello Gurus, > > Every once in a while I run into this nagging little problems that look > easy on > the surface but refuse to be coded. Here's what I have. > I have a sas dataset in which each oservation has the following: > > id amt&1......amt&12 start end > a amtjan97...amtdec97 jun97 nov97 > b amtjan97...amtdec97 feb97 may97 > .......................and so on. > > The "amt" variables are generated via macro and a data step. The "start" > and > "end" variables indicate the beginning and end of activity and VARY FOR > EACH > OBSERVATION. I am trying to get data step logic that will take the start > and end > dates and match these with the appropriate amt& variables to get a sum for > the > activity period. I know I could hard code each varying start and end date > but > there are literally hundreds of start/end dates. Any easy way to do this? > > TIA, > Frank >


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