SAS中文论坛

标题: 多条件限定,选择的变量为日期格式变量 [打印本页]

作者: shiyiming    时间: 2011-4-2 02:44
标题: 多条件限定,选择的变量为日期格式变量
先呈现例子:
[code:2wehqseq]data f001;
input  id        h1  h2        h6        h7        m1 m2        m6        m7        s1 s2        s6        s7;
informat         h1 m1 s1  yymmdd10.;
format h1 m1 s1 yymmdd10.;
datalines;                                                                                               
1        2010/2/23        2        0        4        .        .        .        .        2010/2/22        .        .        4
2        2010/3/3        2        0        3        2010/4/22        2        0        4        .        .        .        .
3        2010/2/27        2        0        4        .        .        .        .        2010/2/27        .        0        4
4        2010/3/10        2        0        3        .        .        .        .        2010/3/10        .        .        3
5        2010/3/17        2        0        4        .        .        .        .        .        .        .        .
6        .        .        .        .        .        .        .        .        .        .        .        .
7        2010/4/7        2        0        4        .        .        .        .        .        .        .        .
8        2010/4/7        2        0        4        .        .        .        .        .        .        .        .
9        2010/6/1        2        0        3        2010/8/12        2        0        4        .        .        .        .
10        2010/5/21        2        1        4        .        .        .        .        .        .        .        .
11        2010/6/17        2        0        1        2010/7/27        2        0        1        .        .        .        .
12        2011/1/5        2        0        4        .        .        .        .        .        .        .        .
13        2010/6/21        2        0        1        2010/9/30        2        0        4        .        .        .        .
14        2010/7/7        2        1        3        2010/9/1        2        1        4        .        .        .        .
15        2010/8/23        2        0        2        2010/10/16        1        0        4        .        .        .        .
16        2010/9/2        2        0        3        2010/10/19        2        0        3        2010/10/26        2        0        3
17        2010/8/31        2        0        4        .        .        .        .        .        .        .        .
18        2010/10/13        2        0        4        .        .        .        .        .        .        .        .
19        2010/11/6        2        0        4        .        .        .        .        .        .        .        .
20        2010/12/23        2        0        4        .        .        .        .        .        .        .        .
;
run;[/code:2wehqseq]
我使用这个条件,结果没法得到理想结果
[code:2wehqseq]if (h2=1 or h6=1 or h7=4 ) then year_fail=h1;
        if (m2=1 or m6=1 or m7=4 ) then year_fail=m1;
        if (s2=1 or s6=1 or s7=4) then year_fail=s1;
                  else year_fail=s1
              informat year_fail yymmdd10.;format year_fail yymmdd10.;
[/code:2wehqseq]
[size=150:2wehqseq][color=#FF0000:2wehqseq]大概意思就如上面条件语句,故请教大侠,指点下。[/color:2wehqseq][/size:2wehqseq]
作者: Qiong    时间: 2011-4-2 09:46
标题: Re: 多条件限定,选择的变量为日期格式变量
你的理想结果是啥?
作者: shiyiming    时间: 2011-4-2 10:37
标题: Re: 多条件限定,选择的变量为日期格式变量
[color=#FF0000:335xw3l1]就是根据h2=1 or h6=1 or h7=4 来决定新变量year_fail的取值(等于h1);
同理,也是根据m2=1 m6=1  m7=4 来决定year_fail取值(等于m1);
也是根据s2=1 s6=1   s7=4 来决定year_fail(等于s1);[/color:335xw3l1]
作者: shiyiming    时间: 2011-4-2 10:59
标题: Re: 多条件限定,选择的变量为日期格式变量
[quote="hwb5258289":23r3jsq5][color=#FF0000:23r3jsq5]就是根据h2=1 or h6=1 or h7=4 来决定新变量year_fail的取值(等于h1);
同理,也是根据m2=1 m6=1  m7=4 来决定year_fail取值(等于m1);
也是根据s2=1 s6=1   s7=4 来决定year_fail(等于s1);[/color:23r3jsq5][/quote:23r3jsq5]
你用的if貌似没什么问题啊
如果if不满足,year_fail怎么取值?
作者: shiyiming    时间: 2011-4-2 11:06
标题: Re: 多条件限定,选择的变量为日期格式变量
其实是有问题的,[quote="hssnow":111kd3vk][quote="hwb5258289":111kd3vk][color=#FF0000:111kd3vk]就是根据h2=1 or h6=1 or h7=4 来决定新变量year_fail的取值(等于h1);
同理,也是根据m2=1 m6=1 m7=4 来决定year_fail取值(等于m1);
也是根据s2=1 s6=1 s7=4 来决定year_fail(等于s1);[/color:111kd3vk][/quote:111kd3vk]
你用的if貌似没什么问题啊
如果if不满足,year_fail怎么取值?[/quote:111kd3vk]
year_fail的取值为yymmdd10.,以上条件若为数值的话是没问题的,但是日期就有问题了,另外,“如果if不满足,year_fail怎么取值?”后面忘记了加 else year_fail=s1.




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2