楼主: walkinggirl
1490 1

[原创博文] 【求助】关于日期变量的问题 [推广有奖]

  • 0关注
  • 0粉丝

大专生

28%

还不是VIP/贵宾

-

威望
0
论坛币
155 个
通用积分
0.0052
学术水平
1 点
热心指数
1 点
信用等级
0 点
经验
448 点
帖子
34
精华
0
在线时间
26 小时
注册时间
2007-4-12
最后登录
2015-9-30

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请教问题如下:
有两个dataset,一个是经济周期的peak、trough时间,另一个是每个code的日期。现在需要确认每个code的日期是在经济周期的哪一个阶段。例如:

Business cycle:

Boom_start              Boom_end             Recession_start         Recession_end
19600101                 19620814                   19640519                  19641227
19800113                 19820320                   19880922                  19890123
...
20030511                  20040609                  20070223                  20090111


Code_date:

Code            Date               State
1                19610103          Boom
2                19880205          Recession
3                19860309          midcycle
4                20050822          midcycle
...

希望得到如下结果:
if  Boom_start<=date<=Boom_end then   state=Boom
if  Recession_start<=date<=Recession_end then state=Recession
else state=midcycle

十分感谢!
二维码

扫码加我 拉你入群

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

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

关键词:日期变量 recession Business dataset cycle Business

回帖推荐

bobguy 发表于2楼  查看完整内容

The simplest way to implement it is to use SAS format. The format approach is more like a function with many 'if ... then ...' statement. In order to use SAS format the date variable would be better defined as SAS date(numeric type) . SAS date is simple a integer value with 1960-1-1 as 0. Here is a sample program you may use it as a template in your problem. data def; length indi ...

本帖被以下文库推荐

沙发
bobguy 发表于 2010-2-6 11:31:36 |只看作者 |坛友微信交流群
walkinggirl 发表于 2010-2-6 06:53
请教问题如下:
有两个dataset,一个是经济周期的peak、trough时间,另一个是每个code的日期。现在需要确认每个code的日期是在经济周期的哪一个阶段。例如:

Business cycle:

Boom_start              Boom_end             Recession_start         Recession_end
19600101                 19620814                   19640519                  19641227
19800113                 19820320                   19880922                  19890123
...
20030511                  20040609                  20070223                  20090111


Code_date:

Code            Date               State
1                19610103          Boom
2                19880205          Recession
3                19860309          midcycle
4                20050822          midcycle
...

希望得到如下结果:
if  Boom_start
The simplest way to implement it is to use SAS format. The format approach is more like a function with many 'if ... then ...' statement.

In order to use SAS format the date variable would be better defined as SAS date(numeric type) . SAS date is simple a integer value with 1960-1-1 as 0.

Here is a sample program you may use it as a template in your problem.

data def;
length     indictor $10.;
infile cards;
type='n';
sexcl='n';
eexcl='n';
fmtname=' econdef';
input date1 : yymmdd8. date2 : yymmdd8.  @;
        indictor='BOOM';
        output;
input date1 : yymmdd8. date2 : yymmdd8.  ;
           indictor='RECESSION';
output;
format     date1 date2  yymmdd10.;
cards;
19600101                 19620814                   19640519                  19641227
19800113                 19820320                   19880922                  19890123
20030511                  20040609                  20070223                  20090111
;

proc format cntlin=def(rename=(date1=start   date2= end  indictor=label ));
run;

data t1;
input Date : yymmdd8.;
econdef=put( Date, econdef.);
format     date  yymmdd10.;
cards;
19610103         
19640519         
19820319         
20090110
20090111
;

proc print; run;
**************output****************;
  Obs          Date    econdef

   1     1961-01-03    BOOM
   2     1964-05-19    RECESSION
   3     1982-03-19    BOOM
   4     2009-01-10    RECESSION
   5     2009-01-11    RECESSION
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

使用道具

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

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

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

GMT+8, 2024-5-15 06:43