Date: Fri, 26 Mar 2010 14:22:46 -0400
Reply-To: Ya Huang <ya.huang@AMYLIN.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ya Huang <ya.huang@AMYLIN.COM>
Subject: Re: Dividing a table in to smaller tables
The following code add a flag in your data, so that every time
the running total exceed 50, flag value increase by 1. With the
flag, you can easily break the data into small piece if indeed
the breakout is needed.
data have;
input name $1-19 id len a;
cards;
damodaranpilla 23 14 14
panickerettan 34 13 27
shivashankaran 32 14 41
karunakaranpilla 989 16 57
muralidharan 36 12 69
keshavannambiar 76 15 84
mohanlal 1 8 92
sreekumaranthampi 54 17 109
ravivarmathamburan 56 18 127
pishardy 88 8 135
velayudhan 344 10 145
aniyankutty 76 11 156
beeranikka 333 10 166
ahmedkutty 656 10 176
pappachan 647 9 185
chackochan 646 10 195
musiliyar 554 9 204
;
data need;
set have;
if _n_=0 then do; runtotal=0; grp=0; end;
runtotal+len;
if runtotal > 50 then do;
grp+1;
runtotal=len;
end;
run;
proc print;
run;
Obs name id len a runtotal grp
1 damodaranpilla 23 14 14 14 0
2 panickerettan 34 13 27 27 0
3 shivashankaran 32 14 41 41 0
4 karunakaranpilla 989 16 57 16 1
5 muralidharan 36 12 69 28 1
6 keshavannambiar 76 15 84 43 1
7 mohanlal 1 8 92 8 2
8 sreekumaranthampi 54 17 109 25 2
9 ravivarmathamburan 56 18 127 43 2
10 pishardy 88 8 135 8 3
11 velayudhan 344 10 145 18 3
12 aniyankutty 76 11 156 29 3
13 beeranikka 333 10 166 39 3
14 ahmedkutty 656 10 176 49 3
15 pappachan 647 9 185 9 4
16 chackochan 646 10 195 19 4
17 musiliyar 554 9 204 28 4
On Fri, 26 Mar 2010 00:34:45 -0700, Friends <sachin.s.nair@GMAIL.COM> wrote:
>Hey All,
>
>I have a dataset named test the snapshot of which is included below.
>I have to divide this table in to smaller tables in such a way that
>the total length of the name field in a table does not exceed 50
>characters
>
> Obs name id len a
>
> 1 damodaranpilla 23 14 14
> 2 panickerettan 34 13 27
> 3 shivashankaran 32 14 41
> 4 karunakaranpilla 989 16 57
> 5 muralidharan 36 12 69
> 6 keshavannambiar 76 15 84
> 7 mohanlal 1 8 92
> 8 sreekumaranthampi 54 17 109
> 9 ravivarmathamburan 56 18 127
> 10 pishardy 88 8 135
> 11 velayudhan 344 10 145
> 12 aniyankutty 76 11 156
> 13 beeranikka 333 10 166
> 14 ahmedkutty 656 10 176
> 15 pappachan 647 9 185
> 16 chackochan 646 10 195
> 17 musiliyar 554 9 204
>
>If you look at the above example,we need to sum up the length of
>variable named "NAME" and if the sum is less than 50 make a separate
>table out of it.For example in the above case the sum of length of
>"NAME" for first three
>observations comes out to be 41 and if we add the length of name for
>the next observation that is the 4 th observation we exceed a length
>boundary of 50.So we will make a table using the first 3
>observation.Now in the second run if we add the length of "NAME" for
>4,5,6 observation it comes out to be 43 now if we add the 7
>observation the sum turns out to be 51 so the table should have only
>observations 4,5,6.This process has to repeat till we reach the end of
>the table.Hope you guys got the problem.
>
>A further extension to this provlem would be that in addition to
>considering only NAME variable there will other variable which need to
>be considered like ZIP,PHONE NUMBER.
>
>
>
>Sachin.