Hi, ID GRP 0001 A 0002 A 0003 A 0004 B 0005 B 0006 0007 B 0008 A 0009 0010 0011 B 0012 0013 D 0014 B 0015 0016 A 0017 0018 A 0019 0020 0021 C 0022 0023 0024 C 0001 0002 0003 0004 0005 I have the dataset above - I want to distribute the IDs to GRP (A or B) given the following conditions. - If the repeated ID value has no assigned GRP then check from other observation if it has GRP value (A or B) and assign the GRP value, if no then assign new GRP. - Distribute the unassigned IDs to GRP (A or B ) given that the GRP must have equal or at least near number of assigned IDs. I know this can be done using loop in SAS but I don't know how to distribute the ID values after counting or getting the ID count on each group Below is the desired output dataset. ID GRP 0001 A 0002 A 0003 A 0004 B 0005 B 0006 C 0007 B 0008 A 0009 C 0010 C 0011 B 0012 C 0013 D 0014 B 0015 B 0016 A 0017 D 0018 A 0019 A 0020 B 0021 C 0022 D 0023 C 0024 C 0001 A 0002 A 0003 A 0004 B 0005 B This part explains the distribution of remaining IDs to the GRP. GRP ID COUNT ID COUNT (1ST ITERATION) ID COUNT (2ND ITERATION) A 6 6 7 B 5 6 7 C 2 6 7 D 5 6 7 REMAINING ID COUNT 10 4 0 TO DISTRIBUTE
... View more