You know that qtr2_demand = '2016-Q4' because I have th Last 8 quarters based on today's date. Below is my code -I tried to used Proc Tabulate to create the output table but there are too many crossing -so i am reverting to Proc Print and redefining the variables. data final(drop=fmgfirstadvdate ord_mail_dt);
merge itemdata(in=a) items1(in=b) po2(in=c);
by baseedp;
format order_dt first_adv_dt mmddyy10.;
if a=1;
order_dt = datepart(ord_mail_dt);
first_adv_dt = datepart(fmgfirstadvdate);
qtr = put(intnx('qtr',order_dt,0,'b'),yyq8.);
weeks = intck('week',order_dt,&lastweek);
if weeks <= 52 then weeks52 = 0;
else if weeks <= 104 then weeks52 = 1;
else if weeks <= 156 then weeks52 = 2;
else if weeks <= 208 then weeks52 = 3;
run;
data newfinal(drop=demandqty demandafterdisc cust_edp_id sales_ord_nr qtr weeks weeks52);
set final;
retain yr0_units yr0_dmd yr1_units yr1_dmd yr2_units yr2_dmd yr3_units yr3_dmd
qtr0_units qtr0_dmd qtr1_units qtr1_dmd qtr2_units qtr2_dmd qtr3_units qtr3_dmd
qtr4_units qtr4_dmd qtr5_units qtr5_dmd qtr6_units qtr6_dmd qtr7_units qtr7_dmd qtr8_units qtr8_dmd;
by baseedp;
if first.baseedp then do;
yr0_units = 0;
yr0_dmd = 0;
yr1_units = 0;
yr1_dmd = 0;
yr2_units = 0;
yr2_dmd = 0;
yr3_units = 0;
yr3_dmd = 0;
qtr0_units = 0;
qtr0_dmd = 0;
qtr1_units = 0;
qtr1_dmd = 0;
qtr2_units = 0;
qtr2_dmd = 0;
qtr3_units = 0;
qtr3_dmd = 0;
qtr4_units = 0;
qtr4_dmd = 0;
qtr5_units = 0;
qtr5_dmd = 0;
qtr6_units = 0;
qtr6_dmd = 0;
qtr7_units = 0;
qtr7_dmd = 0;
qtr8_units = 0;
qtr8_dmd = 0;
end;
select(weeks52);
when(0) do;
yr0_units + demandqty;
yr0_dmd + demandafterdisc;
end;
when(1) do;
yr1_units + demandqty;
yr1_dmd + demandafterdisc;
end;
when(2) do;
yr2_units + demandqty;
yr2_dmd + demandafterdisc;
end;
when(3) do;
yr3_units + demandqty;
yr3_dmd + demandafterdisc;
end;
otherwise;
end;
select(intck('qtr',order_dt,&lastweek));
when(0) do;
qtr0_units + demandqty;
qtr0_dmd + demandafterdisc;
end;
when(1) do;
qtr1_units + demandqty;
qtr1_dmd + demandafterdisc;
end;
when(2) do;
qtr2_units + demandqty;
qtr2_dmd + demandafterdisc;
end;
when(3) do;
qtr3_units + demandqty;
qtr3_dmd + demandafterdisc;
end;
when(4) do;
qtr4_units + demandqty;
qtr4_dmd + demandafterdisc;
end;
when(5) do;
qtr5_units + demandqty;
qtr5_dmd + demandafterdisc;
end;
when(6) do;
qtr6_units + demandqty;
qtr6_dmd = demandafterdisc;
end;
when(7) do;
qtr7_units + demandqty;
qtr7_dmd + demandafterdisc;
end;
when(8) do;
qtr8_units + demandqty;
qtr8_dmd + demandafterdisc;
end;
otherwise;
end;
if last.baseedp then output;
run;
proc print data=newfinal noobs label;
where lateststatus = 'C1' and onhand > 0 and sum(yr0_dmd,yr1_dmd,yr2_dmd,yr3_dmd) > 0;
id first_adv_dt;
var description lateststatus itemno last_po_dt first_po_dt onhand next_po_qty
yr0_units yr0_dmd yr1_units yr1_dmd yr2_units yr2_dmd yr3_units yr3_dmd
qtr0_units qtr0_dmd qtr1_units qtr1_dmd qtr2_units qtr2_dmd qtr3_units qtr3_dmd
qtr4_units qtr4_dmd qtr5_units qtr5_dmd qtr6_units qtr6_dmd qtr7_units qtr7_dmd qtr8_units qtr8_dmd;
run;
... View more