SAS中文论坛

标题: 折扣问题 [打印本页]

作者: shiyiming    时间: 2010-10-15 09:13
标题: 折扣问题
有个超市,不同时间,不同商品,折扣不同, 有两个表如下:

表格a:
货品    种类  分种类  
clothes    A       01
shoes      A       02
food        B       01
makeup   C       01

表格b:
(下表适用于2009年与2010年)
种类  分种类  平时折扣  特殊折扣  特殊折扣开始日期 特殊折扣结束日期
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              20101130
C        01          0.6  

表格c:
购买时间  货品    原价格
20090115  clothes    100
20090115  shoes      100
20090808  food        100
......
20100101  food        100
20101015  makeup   100


现在根据表格a与b,得出表格c打完折扣后,购买需要的钱:
购买时间  货品    原价格  折扣后价
20090115  clothes    100        80
20090115  shoes      100        90
20090808  food        100        40
......
20100101  food        100        50
20101015  makeup   100        60

请教如何完成sas程序,谢谢!
作者: shiyiming    时间: 2010-10-15 12:12
标题: Re: 折扣问题
感觉通过多表查询可以解决,但不理解表B数据的含义
[quote:1kkbwp0f]表格b:
(下表适用于2009年与2010年)
种类 分种类 平时折扣 特殊折扣 特殊折扣开始日期 特殊折扣结束日期
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
A 01 0.6 [/quote:1kkbwp0f]
第一条记录表示商品A 01在20090101-20090201期间的平时折扣是0.9,特殊折扣为0.8;
第二条记录表示商品A 01在20100101-20100201期间的平时折扣是0.9,特殊折扣为0.8;
疑惑的是在20090202-20091231,20100202-20101231期间的平时折扣是多少? 是0.9,还是第六条记录表示的0.6? 如果是0.9那暗示着2年内同一商品的平时折扣保持不变?

另外我猜这不是零售行业的数据,对吗?
作者: shiyiming    时间: 2010-10-15 14:16
标题: Re: 折扣问题
第一条记录表示商品A  01在20090101-20090201处于特殊折扣期,折扣为0.8。20090202-20091231处于平时折扣期,折扣为0.9;
第二条记录表示商品A  01在20100101-20100201处于特殊折扣期,折扣为0.8。20100202-20101231处于平时折扣期,折扣为0.9;
第六条记录表示商品C  01在2009年和2010年的折扣均为0.6
hopewell,这只是一个模型而已,我假设的.
作者: shiyiming    时间: 2010-10-15 15:41
标题: Re: 折扣问题
你问题描述的我不是很理解,这是我按照我理解写的程序,希望对你有用:
data a;
format zl   fzl  pszk tszk tszkksri tszkjssq;
length zl $8. fzl $8. pszk $8. tszk $8.;
input  zl fzl pszk tszk tszkksri tszkjssq;
datalines;
A 01 0.9 0.8 20090101 20090201
A 02 0.9  .  .         .      
B 01 0.5 0.4 20090601 20091231
B 01 0.5 0.4 20100501 20091130
;
run;
proc sort data=a;by zl;run;
data b;
format hp zl fzl;
length hp $8.  zl  $8. fzl $8. ;
input  hp zl fzl;
datalines;
clothes A 01
shoes A 02
food B 01
;
run;
proc sort data=b;by hp;run;
data c;
format gmsj hp yjg;
length gmsj $8. hp $8. yjg $8.;
input gmsj hp yjg;
datalines;
20090115 clothes 100
20090115 shoes 100
20090808 food 100
20100101 food 100
;
run;
proc sort data=c;by hp;run;
data d;
merge b c;
by hp;
run;
proc sort data=d;by zl fzl;run;
data e;
merge a d;
by zl fzl ;
run;
data f;
set e;
a=gmsj > tszkksri and gmsj < tszkjssq;
if a then sjje=yjg*tszk;
else do ;  sjje=yjg*pszk;end;
run;
作者: shiyiming    时间: 2010-10-15 16:01
标题: Re: 折扣问题
谢谢glb34007 , 我的表达不清晰,但你的解答已经帮助我不少了。
作者: shiyiming    时间: 2010-10-15 16:24
标题: 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]
作者: shiyiming    时间: 2010-10-15 17:38
标题: Re: 折扣问题
hopewell, you are really good at SAS. Thank you!




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2