楼主: andyex88
862 3

[问答] SAS时间资料问题的求教 [推广有奖]

  • 0关注
  • 0粉丝

小学生

7%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
36 点
帖子
3
精华
0
在线时间
5 小时
注册时间
2013-5-7
最后登录
2013-5-31

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
请问前辈们小弟刚刚学习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的资料不用做这动作

依此类推

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

二维码

扫码加我 拉你入群

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

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

关键词:actual Event money time vent 学习 资料 money

沙发
yuerqieqie 发表于 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;

使用道具

藤椅
andyex88 发表于 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 ...
谢谢前辈我立马去试试

使用道具

板凳
andyex88 发表于 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的方式但现在前辈的方式我不知道该怎么写

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-21 15:03