BookmarkSubscribeRSS Feed
juanvg1972
Pyrite | Level 9

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

1 REPLY 1
gergely_batho
SAS Employee

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

proc sql;

create index cod_producto on ventas;

quit;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 981 views
  • 0 likes
  • 2 in conversation