Date: Wed, 18 Dec 2002 15:53:29 -0500
Reply-To: Ian Whitlock <WHITLOI1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <WHITLOI1@WESTAT.COM>
Subject: Re: Quiet a Challenge
Content-Type: text/plain; charset="iso-8859-1"
Shiling,
I do not know whether your solution is right or wrong, since I am not really
sure what was asked for. But compare your code with mine. After dropping
the loop indexes i and j from the appropriate datasets, PROC COMPARE shows
my data the same as yours.
The simpler organization follows from synchronizing the reading with the
writing by putting the SET statement in the loop, i.e. reading the chunk of
input that corresponds to the chunk of output.
data t2comp ( drop = i );
array tempvar(6) ;
resum1=1;
resum2=0;
do i = 1 to 6 ;
set t1;
tempvar( i )=age;
if tempvar( i ) <0.05 then do;
tempvar( i ) = 0.05;
resum1 + (-0.05);
end;
else resum2 + tempvar( i );
end ;
do day = 1 to 6;
if tempvar( day ) ne 0.05 then age=tempvar(day)*resum1/resum2;
else age =0.05;
x+ age;
output;
end;
* keep day age x;
run;
Unlike the Iran-contra affair, there is no reason to keep the SET (i.e. old
man Bush) out of the loop.
IanWhitlock@westat.com
-----Original Message-----
From: shiling zhang [mailto:shiling99@YAHOO.COM]
Sent: Monday, December 16, 2002 1:17 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Quiet a Challenge
I post this answer according to 'only' my understanding.
You want to give a assign a 0.05 to any number is less than 0.05 in
age subject to all of them still adds up to 1 within MON.(1) --
SAT.(6).
I assume that data is in MON -- SAT group with any missing. Assume you
know how to convert MON-SAT to 1-6.
If you have a number just a little above 0.05 and at least 1 is below
0.05 like the case in the 3rd group below, you may find that number
still is below 0.05 even after number adjusted.
HTH.
data t1;
input day age;
cards ;
1 0.140183989
2 0.5385789783
3 0.0840869055
4 0.0700724212
5 0.0374633001
6 0.129614406
1 0.1
2 0.2
3 0.3
4 0.3005
5 0.0990
6 0.0005
1 0.1
2 0.2
3 0.3
4 0.3494
5 0.0501
6 0.0005
data t2;
retain;
array tempvar(6) ;
set t1;
i=mod(_n_,6);
if i=0 then i=6;
if i=1 then do;
resum1=1;
resum2=0;
do j = 1 to 6;
tempvar(j)=0;
end;
end;
tempvar( i )=age;
if tempvar( i ) <0.05 then do;
tempvar( i ) = 0.05;
resum1 + (-0.05);
end;
else resum2 + tempvar( i );
if i=6 then do;
do day = 1 to 6;
if tempvar( day ) ne 0.05 then age=tempvar(day)*resum1/resum2;
else age =0.05;
x+ age;
output;
end;
end;
* keep day age x;
run;
proc print; run;
shiva_sas@HOTMAIL.COM (Shiva Kumar) wrote in message
news:<F37H7p6QmL9FLzrz70h000065a5@hotmail.com>...
> Hello All,
>
> I am presently trying to get to do the following thing. I have a data set
> with following values
>
> day %age
> mon 0.140183989
> tue 0.5385789783
> wed 0.0840869055
> thu 0.0700724212
> fri 0.0374633001
> sat 0.129614406
>
> The data has the day and the %age of a component which adds up to 1 for a
> week. I have to check to see if the %age field has a minimum of .05 else I
> have to assign .05 to that day and distribute it to the rest of the week.
I
> havent figured out how I can go back, or even if I am able to do it in two
> steps by creating a seperate row for difference and subtracting it from
> others. It gets complicated if there are more number of days with less
than
> .05 where I have to make sure the sum adds up to 1 even after doing the
> deductions.
>
> I am sure its a question of logic but with SAS experts with tremendous
> knowledge and experience this could be made simpler then it sounds.
>
>
> Thanks in advance.
>
>
> Shiva
>
>
>
>
> _________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail