| Date: | Thu, 24 May 2001 09:36:40 -0700 |
| Reply-To: | "Huang, Ya" <ya.huang@AGOURON.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Huang, Ya" <ya.huang@AGOURON.COM> |
| Subject: | Re: data step |
|
| Content-Type: | multipart/alternative;
|
|---|
How about this:
data xx;
input Id loc1 loc2 loc3 loc4 loc5 day1 day2 day3 day4 day5 tdays;
cards;
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
;
proc print;
data xx;
set xx;
array dd(5) day1-day5;
array tt(5) tt1-tt5;
ttt=tdays;
do i=5 to 1 by -1;
ttt=sum(ttt,-dd(i));
tt(i)=ttt;
end;
do i=1 to 5;
if tt(i) < 0 then
if sum(dd(i),tt(i)) > 0 then dd(i)=sum(dd(i),tt(i));
else dd(i)=.;
end;
run;
options nocenter;
proc print heading=v;
var loc: day: tdays;
run;
--------------------
The SAS System 08:06 Thursday, May 24, 2001 42
t
l l l l l d d d d d d
O o o o o o a a a a a a
b c c c c c y y y y y y
s 1 2 3 4 5 1 2 3 4 5 s
1 3 4 3 . . 2 5 4 . . 11
2 4 3 2 3 . . 1 2 3 . 6
3 4 3 2 1 . . 1 2 4 . 7
4 1 2 3 . . . 2 4 . . 6
5 3 1 1 . . 2 3 2 . . 7
6 4 2 1 2 . 1 5 5 3 . 14
HTH
Ya Huang
-----Original Message-----
From: Jian Mao [mailto:maojianj@HOTMAIL.COM]
Sent: Wednesday, May 23, 2001 6:22 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: data step
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
[text/html]
|