05-08-2013 07:52 AM
, I want to send a survey to our customers based on a random selection, but i'am stuck.
The problem is that a customers can appear within multiple categories (like customerid 1 and 2 in the example below) what can lead to duplicates in the random selection
What i need is a example how to realise a random selection which selects random three customers a category without duplicaties.
I'm using Enterprise Guide 4.3
05-09-2013 02:06 PM
One approach would be:
Assign a pseudo-random number between 0 and 1 (the RANUNI function) to every record.
Sort by customerid and that number (the category will now be in a random order within customerid).
Select the first of each customerid (now have one record per customerid).
Re-sort by category and the random number (the customerids will now be in a random order within category).
Select first 3 in each category.
05-14-2013 10:56 AM
I would usually use a DATA step and a retain statement for that. Something like
RETAIN counter; DROP counter;
IF first.category THEN counter=0;
IF counter <=3 THEN OUTPUT;