|
Mark,
Very helpful. Unfortunately, I didn't do a good job with my sample data.
I also want to bundle small networks together.
Network Count
======= =====
01 8
02 9
03 7
04 11
I want the first three all to be in the first group. For example
Group Networks Count
===== ========== =====
01 01, 02, 03 24
02 04 11
--
Jack N Shoemaker / JShoemaker@Accordant.net
Visit our patient communities at http://www.accordant.com or our corporate
site http://www.accordant.net
-----Original Message-----
From: Terjeson, Mark [mailto:TERJEMW@dshs.wa.gov]
Sent: Monday, September 11, 2000 3:47 PM
To: Jack Shoemaker; 'sas-l'
Subject: RE: Counting and subsetting question
* sample data ;
data table1;
network = '01';
do id=1 to 57;
output;
end;
network = '02';
do id=1 to 14;
output;
end;
network = '03';
do id=1 to 29;
output;
end;
run;
* must sort first to use FIRST. LAST. ;
proc sort data=table1 out=table2;
by network;
run;
data table3(drop=count);
retain count 0
group 0;
set table2;
by network;
if first.network then
do;
group = 1;
count = 0;
end;
if count ge 20 then
do;
group = group + 1;
count = 0;
end;
output;
count = count + 1;
run;
* check results ;
proc freq data=table3;
table network*group / list missing;
run;
* alternate using the mod() function ;
data table3(drop=count);
retain count 0
group 0;
set table2;
by network;
if first.network then
do;
group = 0;
count = 0;
end;
count+1;
if mod(count,20) eq 1 then group+1;
run;
Hope this is helpful,
Mark Terjeson
Washington State Department of Social and Health Services
Division of Research and Data Analysis (RDA)
(360) 902-0741
(360) 902-0705 fax
mailto:terjemw@dshs.wa.gov
> -----Original Message-----
> From: Jack Shoemaker [SMTP:JShoemaker@ACCORDANT.NET]
> Sent: Monday, September 11, 2000 12:01 PM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Counting and subsetting question
>
> Dear SAS-L,
>
> I have a set of 100 people each with an attribute called network. The
> distribution of these people is
>
> Network Count
> ======= =====
> 01 57
> 02 14
> 03 29
>
> I'd like to break these people into groups of no more than twenty, but
> have each group start on a new network boundary. For example,
>
> Network Group Count
> ======= ===== =====
> 01 1 20
> 01 2 20
> 01 3 17
> 02 4 14
> 03 5 20
> 03 6 9
>
> I though this was easy until I tried to show someone else how to do
> this.
> Can one of you experts take me to school? TIA - Jack
> --
> Jack N Shoemaker / JShoemaker@Accordant.net
> Visit our patient communities at http://www.accordant.com or our corporate
> site http://www.accordant.net
|