First of all, huge thanks to PG who helped with my prior question re random sampling post earlier. What makes my question even more complicated is that the same patient may visit mulitple doctors, so my task is to truly RANDOMLY select a unique patient, meaning, one patient can only be RANDOMLY selected ONCE each run, even if the patient visited multiple doctors. That being said, an individual patient can only be selected ONCE RANDOMLY regardless whomever s/he saw. Here is the example, we need to include up to 3 patients for each doctor when the job is run. Assume the same patients saw both Rodger and Jackson (raw data below), 1) if entry related to patient Ted is first selected, any transactions Ted had should not be selected again for Rodger or Jackson 2) if 3 patients were selected for Rodger, they can’t be selected again for Jackson, meaning Jackson’s 3 patients have to be other patients than 3 selected for Rodger (although they also saw Jackson, they can’t be selected again as Rodger has been RANDOMLY selected if that is the case) and if Jackson did not see any other patients (let's also assume this is true in this example), the result for the first week's run would be as follow and the second week would be null if there is no new patients were seen by Rodger and Jackson: Raw Data: Rodger Jack 15/MAR/2015 E401C Rodger Jack 15/MAY/2015 C985C Rodger Ann 04/APR/2016 A215A Rodger Ted 26/JUN/2015 C425C Rodger Ted 23/JUL/2015 C872C Rodger Ted 18/Jul/2015 C532C Rodger Ted 06/Aug/2015 C231C Rodger William 18/Apr/2016 C425C Rodger Donald 16/May/2016 C005C Jackson Jack 15/Feb/2015 E423A Jackson Jack 15/FEB/2015 C985B Jackson Ann 04/Jun/2016 A215D Jackson Ted 26/Jan/2015 C425X Jackson Ted 23/FEB/2015 C872F Jackson Ted 18/OCT/2015 C530Y Jackson Ted 06/Aug/2015 C231C Jackson William 18/Jan/2016 C430C Jackson Donald 29/May/2016 C104D Result from first run: Rodger Jack 15/MAY/2015 C985C Rodger Ann 04/APR/2016 A215A Rodger Ted 26/JUN/2015 C425C Jackson William 18/Jan/2016 C430C Jackson Donald 29/May/2016 C104D As PROC SURVEYSELECT is not available in the HOST SAS environment, my question is how to use data step or macro or SQL to randomly select one transaction and once that transaction is selected, any transactions associated with that patient should be excluded from the population to be selected for the next selection. I have been stuck with this and could not move on. Any further help from anyone to tackle this challenge will be highly appreciated. Thanks in advance. Rodger
... View more