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