Of course, I just didn't know how to do it. The data which I started with were the number of potential costumers which were assigned to each one of the 4 providers in each surge. data WORK.QUERY_FOR_ASIGNA_DATOSS_0000; infile datalines dsd truncover; input SURGE_NUMBER:32. SURGE_K:32. SURGE_T:32. SURGE_U:32. SURGE_L:32. SURGE_TOTAL:32.; datalines; 1 623 832 890 200 2545 2 623 832 610 200 2265 3 623 832 610 200 2265 4 623 832 925 200 2580 5 573 752 1000 200 2525 ;;;; For each surge I added up all of them, getting the sum of each surge, and then I made a simple division to get each percentage. I don't think there's any problem with that so far. Here's the code I used: %_eg_conditional_dropds(EGTASK.QUERY_FOR_ASIGNA_DATOSS_0001);
PROC SQL;
CREATE TABLE EGTASK.QUERY_FOR_ASIGNA_DATOSS_0001 AS
SELECT /* SURGE_NUMBER */
(MONOTONIC()) AS SURGE_NUMBER,
/* PERCENTAGE_K */
(t1.SURGE_K/t1.SURGE_TOTAL) AS PERCENTAGE_K,
/* PERCENTAGE_T */
(t1.SURGE_T/t1.SURGE_TOTAL) AS PERCENTAGE_T,
/* PERCENTAGE_U */
(t1.SURGE_U/t1.SURGE_TOTAL) AS PERCENTAGE_U,
/* PERCENTAGE_L */
(t1.SURGE_L/t1.SURGE_TOTAL) AS PERCENTAGE_L,
/* TOTAL_PERCENTAGE */
((t1.SURGE_K/t1.SURGE_TOTAL)+(t1.SURGE_T/t1.SURGE_TOTAL)+(t1.SURGE_L/t1.SURGE_TOTAL)+(t1.SURGE_U/t1.SURGE_TOTAL))
AS TOTAL_PERCENTAGE
FROM EGTASK.QUERY_FOR_ASIGNA_DATOSS_0000 t1;
QUIT; And here is an example of the results: data WORK.QUERY_FOR_ASIGNA_DATOSS_0001;
infile datalines dsd truncover;
input SURGE_NUMBER:32. PERCENTAGE_K:32. PERCENTAGE_T:32. PERCENTAGE_U:32. PERCENTAGE_L:32. TOTAL_PERCENTAGE:32.;
datalines;
1 0.2447937132 0.3269155206 0.3497053045 0.0785854617 1
2 0.2750551876 0.3673289183 0.2693156733 0.0883002208 1
3 0.2750551876 0.3673289183 0.2693156733 0.0883002208 1
4 0.2414728682 0.3224806202 0.3585271318 0.0775193798 1
5 0.2269306931 0.2978217822 0.396039604 0.0792079208 1
;;;; That's all I have so far -not much tbh-. There we find the surge number, the percentage assigned to each provider and the sum of all percentages to make sure it's always 1. This is the code I wanted to use later which we know for sure it works the way it is done: DATA ASIGNA_DATOS;
SET WORK.VARIABLES;
ARRAY COD{4} $ 1 ('K','T','U','L');
ARRAY PORCENTAJE{4} (0.266, 0.327, 0.137, 0.27);
DO CONTADOR=1 TO N_REGISTROS;
NUM_OLEADA=CEIL(CONTADOR/N_REGISTROS*N_OLEADAS);
AUX=CONTADOR/N_REGISTROS*N_OLEADAS-NUM_OLEADA+1;
IF AUX<PORCENTAJE[1] THEN COD_PROVEEDOR=COD[1];
ELSE IF AUX-PORCENTAJE[1]<PORCENTAJE[2] THEN COD_PROVEEDOR=COD[2];
ELSE IF AUX-PORCENTAJE[1]-PORCENTAJE[2]<=PORCENTAJE[3] THEN COD_PROVEEDOR=COD[3];
ELSE IF AUX-PORCENTAJE[1]-PORCENTAJE[2]-PORCENTAJE[3]<=PORCENTAJE[4] THEN COD_PROVEEDOR=COD[4];
OUTPUT;
END;
RUN; Where OLEADA = SURGE, CONTADOR = COUNTER, PORCENTAJE = PERCENTAGE. You may see how it works (I had a very interesting time decyphering how it worked). It divides the whole number of registers (roughly 70k) into 4 groups as there are 4 providers. Then, in each group, it starts assigning registers to providers (using the codes "K", "T", "U" and "L") until each percentage is filled, and then it switches to the following provider. It does the same for each one of the 4 groups. As you can see the percentages are given at the beggining of the program. I need to input my set of four percentage per surge instead of that prefixed array, repeating the process for each one of the surges.
... View more