Take a look at this and let me know if this is aligned with what you're wanting:
data have;
do num_items=1 to 50;
output;
end;
run;
data prices;
input bulk bulk_price;
datalines;
1 5
2 9
3 13
4 16
;
run;
proc sql noprint;
select bulk_price, max(bulk) into
:price_list separated by ",", :num_prices from prices;
quit;
data want;
set have;
remainder=num_items;
if num_items le &num_prices then
price=1*scan("&price_list", num_items, ",");
else
do;
array arr[&num_prices];
do i=dim(arr) to 1 by -1;
arr[i]=int(remainder/i);
if remainder >=i*arr[i] and arr[i] > 0 then
do;
remainder=sum(remainder, -i*arr[i]);
price=sum(price, arr[i]*scan("&price_list", i, ","));
end;
end;
end;
drop i arr: remainder;
run;
... View more