全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1070 3
2013-05-16
请问前辈们小弟刚刚学习SAS想要询问一些问题

假如我的资料如下

ID   money   actual_time   EVENT_TIME
1      ...          17014           17167
2      ...          17014           17167
3      ...          17045           17167
4      ...          17045           17167
。    。            。                 。
。    。            。                 。
。    。            。                 。

这资料是我将在EVENT_TIME发生时点

的前后半年内的资料都抓了进来

里面的数字是SAS内建的时间函数

现在我想要将EVENT_TIME发生后的六个月

每一个月的资料减去前第六个月的资料

-6 -5 -4 -3-2 -101 23 45 6 7 8 9

也就是假设上面是一条数线

EVENT_TIME是0的那一点

我想将1的资料减掉-5的资料

2的资料减掉-4的资料

0的资料不用做这动作

依此类推

请问各位前被我该怎么做有点卡很久了!

二维码

扫码加我 拉你入群

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

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

全部回复
2013-5-16 21:28:14
data result;
        set input end = eof;
        * Cacluate interval in month between event_time and actual_time;
        * Shift -5 ... -1 0 1 ... 5 to 1 2 ... 11 ;
        month = intck('month', event_time, actual_time) + 6;
        if 1 <= month <= 11

        array mth{*} mth1-mth11;
        retain mth1-mth11;

        * Initialize array;
        do i = 1 to dim(mth);
                mth[i] = 0;
        end;

        * Cumulative money in month;
        mth[month] + money;

        * out0 = cumulative month in event month 0 = mth[6];
        * out1 = post month 1 - pre month 5 = mth[7] - mth[1];
        * ...;
        array out{*} out0-out5;
        if eof then do;
                do i = 1 to dim(out);
                        if i = 1 then do; out[i] = mth[i+5]; end;
                        else do; out[i] = mth[i+5] - mth[i-1]; end;
                end;
                output;
        end;
        keep out0-out5;
run;
二维码

扫码加我 拉你入群

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

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

2013-5-20 13:05:44
yuerqieqie 发表于 2013-5-16 21:28
data result;
        set input end = eof;
        * Cacluate interval in month between event_time and actual_tim ...
谢谢前辈我立马去试试
二维码

扫码加我 拉你入群

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

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

2013-5-23 15:01:36
* Cumulative money in month;
        mth[month] + money;

前辈我想问这句语法的意思为何? 有些不懂

还有如果我将money 改成以下的资料

   fund     stock ticker    weight   actual_time   EVENT_TIME
      aa             11             ...           17014           17167
      aa             21             ...           17014           17167
      aa             11             ...           17045           17167
      aa             21             ...           17045           17167
      bb                .               .              。                 。
      bb                .               .              。                 。
      。                .               .               。                 。

每档基金(ex: aa,bb)有不同的股票ticker 我想将每个ticker的股票的weight

依照之前的例子减去前面月份的资料

然后每档基金作loop

我应该怎么改写呢?

p.s.每个ticker在不同的月份可能会改变

所以可能这个月有 下个月没有

之前是有想过用full join的方式但现在前辈的方式我不知道该怎么写
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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