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
You need to create an index before using modify key= .
proc sql;
create index cod_producto on ventas;
quit;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: