楼主: 3232442590
1988 7

Code question,thanks [推广有奖]

  • 0关注
  • 0粉丝

硕士生

17%

还不是VIP/贵宾

-

威望
0
论坛币
43 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1205 点
帖子
80
精华
0
在线时间
126 小时
注册时间
2015-9-18
最后登录
2019-1-29

楼主
3232442590 发表于 2015-11-12 15:38:40 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
大家好,想请教一下下面的复杂日期形式有什么更简单的写法呢?谢谢!
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;                                                                                                                                         
二维码

扫码加我 拉你入群

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

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

关键词:question thanks Quest Thank Hank question

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

藤椅
Tigflanker 发表于 2015-11-12 16:23:41
  1. data want;
  2.   zdrq = '12AUG12'd;
  3.   zdrq1 = ifc(2011 <= year(zdrq) <= 2024
  4.     ,catx('Q',year(zdrq),ceil(month(zdrq) / 3))
  5.     ,'error');
  6. run;
复制代码
或者把ifc这一句放到SQL中都可以

板凳
Tigflanker 发表于 2015-11-12 16:24:59
请删除,多回复了一帖
Bye SAS.
若有缘,能重聚。

报纸
teqel 发表于 2015-11-12 23:15:04
  1. data a;
  2. format a yymmdd10.;
  3. a='03oct2015'd;
  4. b=put(a, yyq6.);
  5. run;
复制代码
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Tigflanker + 3 + 2 + 1 正解,观点有启发

总评分: 学术水平 + 3  热心指数 + 2  信用等级 + 1   查看全部评分

地板
teqel 发表于 2015-11-12 23:19:11
data a;
format a yymmdd10.;
a='03oct2015'd;
b=put(a, yyq6.);
run;

7
3232442590 发表于 2015-11-15 12:11:48
Tigflanker 发表于 2015-11-12 16:23
或者把ifc这一句放到SQL中都可以
O(∩_∩)O好的,谢谢

8
3232442590 发表于 2015-11-15 12:12:36
teqel 发表于 2015-11-12 23:19
data a;
format a yymmdd10.;
a='03oct2015'd;
O(∩_∩)O谢谢

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 10:45