现有数据为 data sample, 我对其中的商品id做一个统计, 即用
data test;
set sample;
by ITEM_CODE1;
if first.ITEM_CODE1;
run;
得到表 test
test中有n个商品的ITEM_CODE1,然后让sas依次读取表中的商品ITEM_CODE1,然后执行宏 Marco plot,得出的图名称为此商品的 ITEM_CODE1,最后把结果保存在指定文件夹中。
感谢楼下 可~乐朋友的帮助,现修改代码如下,但是sas跑不出来,希望大家帮忙看看:
在sas中输入以下代码,
%Macro plot(itemcode);*此宏为做图,大家可略过,主要就是传递宏变量 &itemcode
data sample1;
set sample;
where ITEM_CODE1="&itemcode";
run;
data sampledate;
merge sample1 store048.date;
by date;
run;
proc sort data=sampledate;
by ITEM_CODE1 date;
run;
data sample11;
set sampledate;
by ITEM_CODE1 date;
if first.date then daily_sales=0;
daily_sales+QTY;
if last.date then output;
run;
data sample11;
set sample11;
keep date daily_sales;
run;
proc sort data=sample11;
by date;
run;
data sampleprice;
merge sample1 store048.date;
by date;
retain netprice;
if not missing(price) then netprice=price;
run;
data sampleprice;
set sampleprice;
keep date netprice;
run;
data sampleprice;
set sampleprice;
by date;
if first.date;
run;
data mergesample;
merge sampleprice sample11;
by date;
run;
title "&itemcode";
proc gplot data=mergesample;
plot netprice*date;
plot2 daily_sales*date;
symbol1 i=join;
symbol2 i=needle;
run;
%mend;
proc sort data=sample out=test(keep=ITEM_CODE1) nodupkey;
by ITEM_CODE1;
run;
%macro test;
%let dsid=%sysfunc(open(work.test,i));
%let rc=%sysfunc(fetch(&dsid));
%do %while(&rc=0);
%let itemcode=%sysfunc(trim(%sysfunc(left(%sysfunc(getvarc(&dsid,1))))));
%plot(&itemcode);
%let rc=%sysfunc(fetch(&dsid));
%end;
%let rc=%sysfunc(close(&dsid));
%mend;
简而言之,就是目前有数据集 sample,和表test, 利用宏将test中的 ITEM_CODE1 值赋予 &itemcode;
将 itemcode 从test中读出,然后执行 marco plot, 循环,最后得到所有的图。
数据表见附件
sas.rar
(492.77 KB)
本附件包括:- sample.sas7bdat
- test.sas7bdat



雷达卡



京公网安备 11010802022788号







