Hi @Beto16,
Would this work for you?
data have;
input Machine $ Date :mmddyy. Load Use;
format Date mmddyy8.;
cards;
A1 02/03/16 160 31
A1 02/18/16 40 83
A1 02/25/17 80 0
A2 02/03/16 150 80
A2 02/18/16 70 70
A2 02/25/17 42 43
;
data want;
set have;
by machine date;
if first.machine then load1=load;
else if use>load>. then load=load1;
retain load1;
drop load1;
run;
This code doesn't use a DO statement, but unlike your suggested code it involves a condition with "greater than."
It's good that you posted an example, but it would be even better if, in addition, you stated the rule ("if ... greater than ..., then ...") in general terms (e.g. "... then use the load value of the first observation of the machine" or "... then use the load value from the previous observation of the same machine" ...).
Edit: Modified the test data for machine A2 a bit to make it more significant.
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.
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.