全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1283 7
2014-03-13
悬赏 30 个论坛币 已解决
Sir : Can you do debug ? THANKS!
How to use one file(monthly.xlsx) to roll cloumn from 191101 to 201103 fix to 24 variables every moving windows, then rename variable(column) name =K1......K24
---------------------------
H201103 outcomes is only  one my outcome ,
I want to be produce many like H201103 files
that involve from H199101 H199102 ...  to H201103.
--------------------------------------------------------------
Monthly.xlsx
IND         199101  199102......     201301    201302
sz1_bm1  -3.45       8.05  .....        5.76         -1.64
sz1_bm2  -1            8.22......        5.77           -2.35
sz1_bm3 -1.93         8.47......         5.68         -1.99
sz1_bm4 -1.86         7.7   .......      6.87          -1.44
sz1_bm5 -3.15         8.36  .....        10.22      -2.61
sz2_bm1 -1.6           9.68  ....         4.5            1.2
sz2_bm2 -2.89          7.18 ....         5.84      -0.19
------------------------------------------------------
H201103 SAS outcomes:
IND             K1         K2   ...................      K23        K24
sz1_bm1     0.69       7.47 ...................      5.76       -1.64
sz1_bm2     1.35       7.32 ....................... 5.77       -2.35
sz1_bm3     0.81       7.07                         5.68        -1.99
sz1_bm4     2.02       6.44                         6.87        -1.44
sz1_bm5     0.8         6.42                        10.22        -2.61
sz2_bm1     1.35        7.53                       4.5             1.2
sz2_bm2      2.39       6.78                      5.84           -0.19
----------------------------------------------------------------------------
* thanks for nomad5's code*

%macro m(v);


%lety=%substr(&v.,1,4);


%letm=%substr(&v.,5,2);


%doi=1 %to 24;


    %let mf=%sysfunc(putn(%eval(&m.+&i.-1),z2.));


    %if &mf.>24 %then %do;


        %let mf=%sysfunc(putn(%eval(&mf.-24),z2.));


        %let yf=%eval(&y.+2);


    %end;


    %else %if &mf.>12 %then %do;


        %let mf=%sysfunc(putn(%eval(&mf.-12),z2.));


        %let yf=%eval(&y.+1);


    %end;


    %else %let yf=&y.;


     ,t1."&yf.&mf."n asK&i.


      %end;


%mend m;


/*%m(201103);*/


proc sql noprint;


    create table test as


   select t1.IND


       %m(201103)


    from work.monthly t1


    ;


quit;


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-3-13 19:26:16
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-3-14 11:20:30
复制代码
附件列表
LOG.JPG

原图尺寸 59.02 KB

LOG.JPG

LOG.JPG

原图尺寸 59.02 KB

LOG.JPG

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-3-14 16:50:37
OK! Thank for your help.
You use the simply pro sql through %m(201103)

BUT : H201103 outcomes is only  one my outcome ,
I want to be produce many like H201103 files
that include from H199101 H199102 ...  to H201103.

I must excute 243 times of %macro : from %m(199101) to %m(201103)
So must  consture  the another macro in this section (proc sql):
THS!

/*%m(201103);*/
proc sql noprint;
     create table test as
     select t1.IND
        %m(201103)
    from work.monthly t1;
quit;

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-3-14 18:10:28
3qsir 发表于 2014-3-14 16:50
OK! Thank for your help.
You use the simply pro sql through %m(201103)
you can create a macro to repeat this code



%macro a;
%do i=199101 %to 201103;
%macro m(v);
%let y=%substr(&v.,1,4);
%let m=%substr(&v.,5,2);
%do i=1 %to 24;
      %let mf=%sysfunc(putn(%eval(&m.+&i.-1),z2.));
      %if &mf.>24 %then %do;
        %let mf=%sysfunc(putn(%eval(&mf.-24),z2.));
        %let yf=%eval(&y.+2);
    %end;
    %else %if &mf.>12 %then %do;
        %let mf=%sysfunc(putn(%eval(&mf.-12),z2.));
        %let yf=%eval(&y.+1);
    %end;
    %else %let yf=&y.;
      ,t1.%sysfunc(cats(%bquote('&yf.&mf.'), n)) as K&i.
  %end;
%mend m;

/*%m(201103);*/
proc sql noprint;
    create table test&i as
     select t1.IND
     %m(&i)
     from work.monthly t1
    ;
quit;
%end;
%mend a;
%a;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-3-14 19:34:18
BUG !!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群