我在座右铭上有着明显的变数,我需要从各个部分开始,用具体的措辞结束。
起始体为“proc sql”,而终止舱位为“quit;”在两者之间的所有线均应从名单上提取;
row = proc sql;
create table answer_1_stg1 as
select distinct a.CUSTOMER_HIERARCHY_LVL2_CD
,b.brand_cd
,b.category_cd
,a.promo_mechanic_nm
,a.promo_mechanic_desc
,sum(b.invoice_qty) as sum_invoice
,avg(b.invoice_qty) as avg_invoice
,max(b.invoice_qty) as max_invoice
,min(b.invoice_qty) as min_invoice
from promo as a
left join invoice as b
on
a.CUSTOMER_HIERARCHY_LVL2_CD=b.CUSTOMER_HIERARCHY_LVL2_CD and
a.basecode=b.basecode and
a.SALESORG_CD=b.SALESORG_CD and
a.LOCATION_CD=b.LOCATION_CD
and b.INVOICE_DT between a.event_start_dt and a.event_end_dt
where year(a.event_start_dt) = 2017 and year(b.INVOICE_DT) = 2017
group by a.CUSTOMER_HIERARCHY_LVL2_CD
,b.brand_cd
,b.category_cd
,a.promo_mechanic_nm
,a.promo_mechanic_desc;
quit;
%sort(answer_1_stg1,descending sum_invoice);
proc sql;
create table answer_1_stg2 as
select distinct promo_mechanic_desc
,sum(sum_invoice) as total
from answer_1_stg1;
quit;
我只需要两条插手,即“proc sql”和“quit”。 最后名单也一样:
lt = [ proc sql;
create table answer_1_stg1 as
select distinct a.CUSTOMER_HIERARCHY_LVL2_CD
,b.brand_cd
,b.category_cd
,a.promo_mechanic_nm
,a.promo_mechanic_desc
,sum(b.invoice_qty) as sum_invoice
,avg(b.invoice_qty) as avg_invoice
,max(b.invoice_qty) as max_invoice
,min(b.invoice_qty) as min_invoice
from promo as a
left join invoice as b
on
a.CUSTOMER_HIERARCHY_LVL2_CD=b.CUSTOMER_HIERARCHY_LVL2_CD and
a.basecode=b.basecode and
a.SALESORG_CD=b.SALESORG_CD and
a.LOCATION_CD=b.LOCATION_CD
and b.INVOICE_DT between a.event_start_dt and a.event_end_dt
where year(a.event_start_dt) = 2017 and year(b.INVOICE_DT) = 2017
group by a.CUSTOMER_HIERARCHY_LVL2_CD
,b.brand_cd
,b.category_cd
,a.promo_mechanic_nm
,a.promo_mechanic_desc;
quit; , proc sql;
create table answer_1_stg2 as
select distinct promo_mechanic_desc
,sum(sum_invoice) as total
from answer_1_stg1;
quit; ]
我试图操作以下代码,但只将每一行中的第一部印到清单中:
fm = []
for i in row.split(
):
if "proc sql" in i:
print()
fm.append(i.strip())