DATA Step, Macro, Functions and more

Error updating table vía set/modify key=

Reply
Frequent Contributor
Posts: 122

Error updating table vía set/modify key=

Hi,

I have a master table called ventas that I want to update based on a lookup table called producto, the field to combine datasets is cod_producto.

I want to update the rows of ventas in which ventas.cod_producto = productos.cod_producto I am doing a set + modify key= and it doesn't work.

This is the code:

%let fecha_ini = %sysevalf(%sysfunc(date()) - 900);

%put fecha_ini = &fecha_ini;

/* Crearting dataset ventas */

data ventas(drop=i);

do i=1 to 10000000;

fecha = &fecha_ini + round(900*ranuni(1));

cod_producto = compress('P'||(round(ranuni(1)*1000)+1));

cod_centro = compress('C'||round(ranuni(1)*100));

hc_unidades = round(ranuni(1)*9) + 1;

format fecha ddmmyyn8.;

output;

end;

run;

/* Crearting dataset ventas */

data productos(drop=i);

do i = 1 to 1001;

cod_producto = compress('P'||i);

hc_precio = round(ranuni(1)*400) + 100;

output;

end;

run;

/* Updating datasets ventas */

data ventas;  

   set productos;  /* lookpup */

   modify ventas key=cod_producto;   /* master */

   if _iorc_ = 0 then do; /* hay coincidencia */

    hc_ventas = hc_unidades*hc_precio;

   end;

   else do;

    hc_ventas = 0;

   end;

run;

The error:

'No defined variables for file ventas'

Can anybody help me??

Thanks in advance

SAS Employee
Posts: 340

Re: Error updating table vía set/modify key=

Posted in reply to juanvg1972

You need to create an index before using  modify    key= .

proc sql;

create index cod_producto on ventas;

quit;

Ask a Question
Discussion stats
  • 1 reply
  • 162 views
  • 0 likes
  • 2 in conversation