|
|
6#

楼主 |
发表于 2010-10-15 16:24:00
|
只看该作者
Re: 折扣问题
[code:3gsxbv2i]data a;
input description :$10. category $ sub_category $;
datalines;
clothes A 01
shoes A 02
food B 01
makeup C 01
;
data b;
infile datalines truncover;
input category $ sub_category $ discount special_discount start_date :yymmdd8. end_date :yymmdd8.;
format start_date end_date yymmdd10.;
datalines;
A 01 0.9 0.8 20090101 20090201
A 01 0.9 0.8 20100101 20100201
A 02 0.9
B 01 0.5 0.4 20090601 20091231
B 01 0.5 0.4 20100501 20091130
C 01 0.6
;
data c;
input date yymmdd8. goods :$10. price;
format date yymmdd10.;
datalines;
20090115 clothes 100
20090115 shoes 100
20090808 food 100
20100101 food 100
20101015 makeup 100
;
proc sql;
create table temp as
select one.*, two.discount
from (select c.*, category, sub_category
from c left join a on upcase(goods)=upcase(description)) one
left join
(select distinct category, sub_category, discount from b) two
on one.category=two.category and one.sub_category=two.sub_category;
create table out as
select one.date, one.goods, one.price,
case
when missing(special_discount) then one.discount*price
else special_discount*price
end as new_price
from temp one left join
(select * from b
where not missing(special_discount)) two
on one.category=two.category and one.sub_category=two.sub_category
and start_date<=date<=end_date;
drop table temp;
quit;[/code:3gsxbv2i] |
|