SunnyIving 发表于 2015-8-24 13:40
上代码
PROC IMPORT OUT= WORK.work1
DATAFILE= "work1.csv"
DBMS=CSV REPLACE;
GETNAMES=YES;
DATAROW=2;
RUN;
%macro city_func(city);
%macro index_func(index);
data &city.;
set work1(keep =time &city._&index. where= (&city._&index.<>.));
run;
/*选出最近的三个值*/
proc sort data= &city.;
by descending time ;
run;
data &city.1;
set &city.(obs=3 keep=time &city._&index.);
/*input label $8.;*/
/*cards;*/
/*recent1*/
/*recent2 */
/*recent3*/
/*;*/
run;
proc transpose data= &city.1 out= &city.1;
/*id label;*/
var &city._&index.;
run;
/*选出最大最小值*/
proc sql;
create table &city.2 as
select max( &city._&index.) as max_value, min( &city._&index.) as min_value
from &city.;
quit;
/*合并五个子变量*/
data &city.;
length city $25.;
city=" &city.";
merge &city.1 &city.2;
run;
data total;
set total &city.;
run;
%mend;
%mend ;
%index_func(price)
%index_func(revenue)
%index_func(sales)
%index_func(..)
%index_func(..)
%city_func(beijing)
%city_func(tianjin)
%city_func(shijiazhuang)
%city_func(taiyuan)
%city_func(huhehaote)
%city_func(shenyang)
........