Good observation. Some of the suggestions so far may work. However ...
If it is important to maintain the current order of the observations, and
If all values of your REMARK variable are non-blank,
you could try it this way:
data want;
conclusion = 'READY TO SELL';
do until(last.Part_No);
set have;
by Part_No;
if remark = 'Hold in STOCK' then conclusion = remark;
end;
do until(last.Part_No);
set have;
by Part_No;
output;
end;
run;
What is the logic behind that conclusion='READY TO SELL' for Part_No =kk33 ?
Ohhh, I'm sorry , That was my mistake , Please consider below one.
I've a data like below
Part_No Remark
kk12 READY TO SELL
kk12 Hold in STOCK
kk22 READY TO SELL
kk22 READY TO SELL
kk22 Hold in STOCK
kk33 Hold in STOCK
kk33 READY TO SELL
I need a output like
Part_No Remark conclusion
kk12 READY TO SELL Hold in STOCK
kk12 Hold in STOCK Hold in STOCK
kk22 READY TO SELL Hold in STOCK
kk22 READY TO SELL Hold in STOCK
kk22 Hold in STOCK Hold in STOCK
kk33 Hold in STOCK Hold in STOCK
kk33 READY TO SELL Hold in STOCK
Please suggest on this
Please try the below code, only change to my previous code is i included an additional proc sort step
data have;
input Part_No$ Remark&$100.;
cards;
kk12 READY TO SELL
kk12 Hold in STOCK
kk22 READY TO SELL
kk22 READY TO SELL
kk22 Hold in STOCK
kk33 Hold in STOCK
kk33 READY TO SELL
;
PROC SORT DATA=have;
BY Part_No DESCENDING Remark;
RUN;
data want;
do until(last.Part_No);
set have;
by Part_No;
if last.Part_No then conclusion=Remark;
end;
do until(last.Part_No);
set have;
by Part_No;
output;
end;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.