全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1959 7
2015-11-12
大家好,想请教一下下面的复杂日期形式有什么更简单的写法呢?谢谢!
proc sql;                                                                                                                                    
create table A as                                                                                                                             
select                                                                                                                                       
case when year(zdrq) in (2011) and month(zdrq) in (1,2,3) then '2011Q1'
when year(zdrq) in (2011) and month(zdrq) in (4,5,6) then '2011Q2'      
when year(zdrq) in (2011) and month(zdrq) in (7,8,9) then '2011Q3'      
when year(zdrq) in (2011) and month(zdrq) in (10,11,12) then '2011Q4'   
when year(zdrq) in (2012) and month(zdrq) in (1,2,3) then '2012Q1'      
when year(zdrq) in (2012) and month(zdrq) in (4,5,6) then '2012Q2'      
when year(zdrq) in (2012) and month(zdrq) in (7,8,9) then '2012Q3'      
when year(zdrq) in (2012) and month(zdrq) in (10,11,12) then '2012Q4'   
when year(zdrq) in (2013) and month(zdrq) in (1,2,3) then '2013Q1'      
when year(zdrq) in (2013) and month(zdrq) in (4,5,6) then '2013Q2'      
when year(zdrq) in (2013) and month(zdrq) in (7,8,9) then '2013Q3'      
when year(zdrq) in (2013) and month(zdrq) in (10,11,12) then '2013Q4'   
when year(zdrq) in (2014) and month(zdrq) in (1,2,3) then '2014Q1'      
when year(zdrq) in (2014) and month(zdrq) in (4,5,6) then '2014Q2'      
when year(zdrq) in (2014) and month(zdrq) in (7,8,9) then '2014Q3'      
when year(zdrq) in (2014) and month(zdrq) in (10,11,12) then '2014Q4'   
when year(zdrq) in (2015) and month(zdrq) in (1,2,3) then '2015Q1'      
when year(zdrq) in (2015) and month(zdrq) in (4,5,6) then '2015Q2'      
when year(zdrq) in (2015) and month(zdrq) in (7,8,9) then '2015Q3'      
when year(zdrq) in (2015) and month(zdrq) in (10,11,12) then '2015Q4'   
when year(zdrq) in (2016) and month(zdrq) in (1,2,3) then '2016Q1'      
when year(zdrq) in (2016) and month(zdrq) in (4,5,6) then '2016Q2'      
when year(zdrq) in (2016) and month(zdrq) in (7,8,9) then '2016Q3'      
when year(zdrq) in (2016) and month(zdrq) in (10,11,12) then '2016Q4'   
when year(zdrq) in (2017) and month(zdrq) in (1,2,3) then '2017Q1'      
when year(zdrq) in (2017) and month(zdrq) in (4,5,6) then '2017Q2'      
when year(zdrq) in (2017) and month(zdrq) in (7,8,9) then '2017Q3'      
when year(zdrq) in (2017) and month(zdrq) in (10,11,12) then '2017Q4'   
when year(zdrq) in (2018) and month(zdrq) in (1,2,3) then '2018Q1'      
when year(zdrq) in (2018) and month(zdrq) in (4,5,6) then '2018Q2'      
when year(zdrq) in (2018) and month(zdrq) in (7,8,9) then '2018Q3'      
when year(zdrq) in (2018) and month(zdrq) in (10,11,12) then '2018Q4'   
when year(zdrq) in (2019) and month(zdrq) in (1,2,3) then '2019Q1'      
when year(zdrq) in (2019) and month(zdrq) in (4,5,6) then '2019Q2'      
when year(zdrq) in (2019) and month(zdrq) in (7,8,9) then '2019Q3'      
when year(zdrq) in (2019) and month(zdrq) in (10,11,12) then '2019Q4'   
when year(zdrq) in (2020) and month(zdrq) in (1,2,3) then '2020Q1'      
when year(zdrq) in (2020) and month(zdrq) in (4,5,6) then '2020Q2'      
when year(zdrq) in (2020) and month(zdrq) in (7,8,9) then '2020Q3'      
when year(zdrq) in (2020) and month(zdrq) in (10,11,12) then '2020Q4'   
when year(zdrq) in (2021) and month(zdrq) in (1,2,3) then '2021Q1'      
when year(zdrq) in (2021) and month(zdrq) in (4,5,6) then '2021Q2'      
when year(zdrq) in (2021) and month(zdrq) in (7,8,9) then '2021Q3'      
when year(zdrq) in (2021) and month(zdrq) in (10,11,12) then '2021Q4'
when year(zdrq) in (2022) and month(zdrq) in (1,2,3) then '2022Q1'      
when year(zdrq) in (2022) and month(zdrq) in (4,5,6) then '2022Q2'      
when year(zdrq) in (2022) and month(zdrq) in (7,8,9) then '2022Q3'      
when year(zdrq) in (2022) and month(zdrq) in (10,11,12) then '2022Q4'
when year(zdrq) in (2023) and month(zdrq) in (1,2,3) then '2023Q1'      
when year(zdrq) in (2023) and month(zdrq) in (4,5,6) then '2023Q2'      
when year(zdrq) in (2023) and month(zdrq) in (7,8,9) then '2023Q3'      
when year(zdrq) in (2023) and month(zdrq) in (10,11,12) then '2023Q4'
when year(zdrq) in (2024) and month(zdrq) in (1,2,3) then '2024Q1'      
when year(zdrq) in (2024) and month(zdrq) in (4,5,6) then '2024Q2'      
when year(zdrq) in (2024) and month(zdrq) in (7,8,9) then '2024Q3'      
when year(zdrq) in (2024) and month(zdrq) in (10,11,12) then '2024Q4'
else 'error' end as zdrq                                                                                                                     
,dktx                                                                                                                                         
from tzyh.Dbdktz;                                                                                                                             
quit;                                                                                                                                         
二维码

扫码加我 拉你入群

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

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

全部回复
2015-11-12 16:12:28
我记得SAS SQL中也是支持put、input的
等等,你这仅仅是个时间信息压缩啊,有规律又不分组的东西当然优先data步循环搞定啊。
二维码

扫码加我 拉你入群

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

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

2015-11-12 16:23:41
复制代码
或者把ifc这一句放到SQL中都可以
二维码

扫码加我 拉你入群

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

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

2015-11-12 16:24:59
请删除,多回复了一帖
二维码

扫码加我 拉你入群

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

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

2015-11-12 23:15:04
复制代码
二维码

扫码加我 拉你入群

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

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

2015-11-12 23:19:11
data a;
format a yymmdd10.;
a='03oct2015'd;
b=put(a, yyq6.);
run;
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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