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 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 22 May 2006 21:28:53 -0500
Reply-To:     Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jiann-Shiun Huang <Jiann-Shiun.Huang@AMERUS.COM>
Subject:      Re: random delet from subgroups
Comments: To: Ei-Wen Chang <ei-wen_chang@CTB.COM>
Content-Type: text/plain; charset=US-ASCII

Ei-Wen:

Here is an implementation and its result:

data excluse; infile cards missover; input @1 form $2. @4 grade @6 ethnicity $1. @9 del_n; cards; A1 2 H 5 A1 2 I 5 A1 3 B 9 A3 2 8 A3 7 A 6 ;

proc sort data=excluse; by form grade ethnicity; run;

proc print data=excluse; run;

%let GroupSize=20;

Data std; do i=1 to &GroupSize; form='A1'; grade=2; ethnicity='H'; output; form='A1'; grade=2; ethnicity='I'; output; form='A1'; grade=3; ethnicity='B'; output; form='A1'; grade=3; ethnicity='I'; output; form='A3'; grade=2; ethnicity='A'; output; form='A3'; grade=2; ethnicity='I'; output; form='A3'; grade=7; ethnicity='A'; output; form='A3'; grade=7; ethnicity='A'; output; form='A3'; grade=7; ethnicity='B'; output; end; run;

proc sql; create table stdSummary as select distinct A.form, A.grade, A.ethnicity, count(*) as Count, B.del_n from std A left join excluse B on A.form eq B.form and A.grade eq B.grade and (A.ethnicity eq B.ethnicity or B.ethnicity eq " ") group by A.form, A.grade, A.ethnicity; quit;

%let seed=123;

data Result(keep=i form grade ethnicity); retain delCount Remain; set stdSummary stdA; by form grade ethnicity; if first.ethnicity then do; if del_n gt 0 then do; Remain=Count; delCount=del_n; end; else do; Remain=0; delCount=0; end; end; else do; if delCount eq 0 then output; else do; if delCount gt ranuni(&seed)*Remain then output; else do; Remain=Remain-1; delCount=delCount-1; end; end; end; run;

proc print data=Result; run;

***** OUTPUT ***** The SAS System 17:58 Monday, May 22, 2006 139

Obs form grade ethnicity del_n

1 A1 2 H 5 2 A1 2 I 5 3 A1 3 B 9 4 A3 2 8 5 A3 7 A 6

The SAS System 17:58 Monday, May 22, 2006 140

Obs form grade ethnicity i

1 A1 2 H 9 2 A1 2 H 5 3 A1 2 H 11 4 A1 2 H 16 5 A1 2 H 12 6 A1 2 H 18 7 A1 2 H 20 8 A1 2 H 19 9 A1 2 H 14 10 A1 2 H 13 11 A1 2 H 8 12 A1 2 H 2 13 A1 2 H 3 14 A1 2 H 4 15 A1 2 H 7 16 A1 2 I 8 17 A1 2 I 17 18 A1 2 I 4 19 A1 2 I 2 20 A1 2 I 5 21 A1 2 I 14 22 A1 2 I 1 23 A1 2 I 7 24 A1 2 I 9 25 A1 2 I 18 26 A1 2 I 13 27 A1 2 I 19 28 A1 2 I 16 29 A1 2 I 6 30 A1 2 I 11 31 A1 3 B 4 32 A1 3 B 8 33 A1 3 B 5 34 A1 3 B 16 35 A1 3 B 18 36 A1 3 B 19 37 A1 3 B 6 38 A1 3 B 9 39 A1 3 B 17 40 A1 3 B 14 41 A1 3 B 15 42 A1 3 I 4 43 A1 3 I 14 44 A1 3 I 7 45 A1 3 I 13 46 A1 3 I 2 47 A1 3 I 12 48 A1 3 I 6 49 A1 3 I 19 50 A1 3 I 11 51 A1 3 I 3

The SAS System 17:58 Monday, May 22, 2006 141

Obs form grade ethnicity i

52 A1 3 I 10 53 A1 3 I 18 54 A1 3 I 5 55 A1 3 I 20 56 A1 3 I 9 57 A1 3 I 17 58 A1 3 I 16 59 A1 3 I 8 60 A1 3 I 1 61 A1 3 I 15 62 A3 2 A 14 63 A3 2 A 13 64 A3 2 A 19 65 A3 2 A 1 66 A3 2 A 9 67 A3 2 A 17 68 A3 2 A 18 69 A3 2 A 16 70 A3 2 A 8 71 A3 2 A 20 72 A3 2 A 4 73 A3 2 A 15 74 A3 2 I 2 75 A3 2 I 13 76 A3 2 I 12 77 A3 2 I 11 78 A3 2 I 18 79 A3 2 I 9 80 A3 2 I 20 81 A3 2 I 17 82 A3 2 I 16 83 A3 2 I 8 84 A3 2 I 4 85 A3 2 I 15 86 A3 7 A 7 87 A3 7 A 12 88 A3 7 A 6 89 A3 7 A 12 90 A3 7 A 3 91 A3 7 A 6 92 A3 7 A 3 93 A3 7 A 11 94 A3 7 A 11 95 A3 7 A 20 96 A3 7 A 5 97 A3 7 A 10 98 A3 7 A 5 99 A3 7 A 19 100 A3 7 A 19 101 A3 7 A 18 102 A3 7 A 9

The SAS System 17:58 Monday, May 22, 2006 142

Obs form grade ethnicity i

103 A3 7 A 18 104 A3 7 A 9 105 A3 7 A 10 106 A3 7 A 17 107 A3 7 A 20 108 A3 7 A 17 109 A3 7 A 16 110 A3 7 A 8 111 A3 7 A 16 112 A3 7 A 4 113 A3 7 A 8 114 A3 7 A 2 115 A3 7 A 4 116 A3 7 A 15 117 A3 7 A 1 118 A3 7 A 2 119 A3 7 A 15 120 A3 7 B 7 121 A3 7 B 14 122 A3 7 B 13 123 A3 7 B 3 124 A3 7 B 6 125 A3 7 B 12 126 A3 7 B 11 127 A3 7 B 5 128 A3 7 B 10 129 A3 7 B 20 130 A3 7 B 19 131 A3 7 B 9 132 A3 7 B 18 133 A3 7 B 17 134 A3 7 B 1 135 A3 7 B 2 136 A3 7 B 4 137 A3 7 B 8 138 A3 7 B 16 139 A3 7 B 15

J S Huang 1-515-557-3987 fax 1-515-557-2422

>>> Ei-Wen Chang <ei-wen_chang@CTB.COM> 05/22/06 8:09 PM >>> I have to random delete some observations in subgroups from a master data (STD). The rules are like following.

If form='A1', grade=2, ethnicity=H or I then random delete 5 cases from this subgroup. If form='A1', grade=3, ethnicity=B then random delete 9 cases from this subgroup. If form='A3', grade=2, then random delete 8 cases from this subgroup. (no target ethnicity) If form='A3', grade=7, and ethnicity='A' then random delete 6 cases from this subgroup.

There are more form, grade, and ethnicity combinations that needs to be excluded, so I don't want to hard code. If anyone can give me some advices, I will appreciate your help. Following are my sample data.

data excluse; infile cards missover; input @1 form $2. @4 grade @6 ethnicity $2. @9 del_n; cards; A1 2 HI 5 A1 3 B 9 A3 2 8 A3 7 A 6 ;

Data std; do i=1 to 20; form='A1'; grade=2; ethnicity='H'; output; form='A1'; grade=2; ethnicity='I'; output; form='A1'; grade=3; ethnicity='B'; output; form='A1'; grade=3; ethnicity='I'; output; form='A3'; grade=2; ethnicity='A'; output; form='A3'; grade=2; ethnicity='I'; output; form='A3'; grade=7; ethnicity='A'; output; form='A3'; grade=7; ethnicity='A'; output; form='A3'; grade=7; ethnicity='B'; output; end; run;

Ei-Wen


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