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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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