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 2001, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 24 May 2001 19:05:22 -0400
Reply-To:     Jonathan Siegel <Jonathan.Siegel@PFIZER.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jonathan Siegel <Jonathan.Siegel@PFIZER.COM>
Subject:      Re: data step
Comments: To: Jian Mao <maojianj@HOTMAIL.COM>

Here's another solution:

data yy; set xx; array loc{5} loc1-loc5; array days{5} day1-day5; array loctype{4} house apt otherplc homeless; cumdays=0; do i=5 to 1 by -1 while (cumdays lt tdays); if loc{i} ne . then do; loctype{loc{i}}=sum(loctype{loc{i}},min(days{i}, tdays-cumdays)); cumdays+min(days{i},tdays-cumdays); end; end; keep id house apt otherplc homeless tdays; run;

proc print data=yy; run;

OBS ID TDAYS HOUSE APT OTHERPLC HOMELESS

1 1 11 . . 6 5 2 2 6 . 2 4 . 3 3 7 4 2 1 . 4 4 6 . 2 4 . 5 5 7 5 . 2 . 6 6 14 5 8 . 1

Hope this helps.

Jonathan Siegel Pfizer Clinical Research and Development Ann Arbor Laboratories 734.622.3982

On Thu, 24 May 2001 01:21:51 -0000, Jian Mao <maojianj@HOTMAIL.COM> wrote:

>I have data like this: > >Id loc1 loc2 loc3 loc4 loc5 day1 day2 day3 day4 day5 tdays >01 3 4 3 . . 10 5 4 . . 11 >02 4 3 2 3 . 6 5 2 3 . 6 >03 4 3 2 1 . 4 5 2 4 . 7 >04 1 2 3 . . 5 2 4 . . 6 >05 3 1 1 . . 4 3 2 . . 7 >06 4 2 1 2 . 10 5 5 3 . 14 > >The variables, "loc1 - loc5" are residential locations with 4-categories >(1=house, 2=apt, 3=other place, 4=homeless). "day1 - day5" are number of >days lived in each location. > >Task: > >To cumulate number of days from loc5 to loc1 (go backwards) by category >(house, apt, others, homeless) across all 5-locations, but TOTAL number of >days in all categories across all locations should equal to "tdays". > >E.g., for id 01, day5 and day4 are missing. For day3, he had 4 days in >"other place" (3=other place at "loc3); For day2, he had 5 days as >"homeless" (4=homeless at loc2); Up to now, we cummulated 9 days by adding >4 days and 5 days, which is 2-days shorter than "tdays"=11. So we need to >extract 2 more days from day1 (at loc1=3="other place"). > >So for id 01, here is what we should get: 6 days (4 + 2) in "other place", >and 5 days as "homeless", the total # of days in all categories across all >locations is therefore 11 days, which is equal to "tdays=11". > >I will appreciate so much if someboby at the list give a help. > >Thank you!!! > >Jian Ja > >_________________________________________________________________ >Get your FREE download of MSN Explorer at http://explorer.msn.com


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