全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1667 1
2010-02-06
请教问题如下:
有两个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

十分感谢!
二维码

扫码加我 拉你入群

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

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

全部回复
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
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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