楼主: rockfido
1704 5

[问答] what does this sql statement mean? [推广有奖]

  • 0关注
  • 0粉丝

已卖:1754份资源

博士生

32%

还不是VIP/贵宾

-

威望
0
论坛币
2715 个
通用积分
0.0341
学术水平
1 点
热心指数
1 点
信用等级
0 点
经验
4441 点
帖子
201
精华
0
在线时间
202 小时
注册时间
2008-8-29
最后登录
2024-11-1

楼主
rockfido 在职认证  发表于 2012-7-20 06:27:58 |AI写论文
100论坛币
was reading some sql code (may not be valid in sas proc sql):

cast((Date1+2 - Date2 month(4)) as int) - suppose date1 = 2011-07-15 and date2 = 2011-06-01, then what is the output?


googled a lit bit and looks like month(4) will be returning value of 1?

but if month(4) will returning value of 1, what does the left mean?

最佳答案

farmman60 查看完整内容

I try to answer your question, first of all, cast function belongs to SQL function, which convert an expression from one data type to another, not SAS function, so it could not be used in SAS, Both SQL and SAS have month function, normally we use month function as month(date), result will be month, for example, month('05Mar2012'd) will get 3, both in SAS and SQL. In SQL, month(0) will get 1, so I ...
关键词:statement Statemen Statem State This sql

沙发
farmman60 发表于 2012-7-20 06:27:59
I try to answer your question, first of all, cast function belongs to SQL function, which convert an expression from one data type to another, not SAS function, so it could not be used in SAS,  Both SQL and SAS have month function, normally we use month function as month(date), result will be month, for example, month('05Mar2012'd) will get 3, both in SAS and SQL. In SQL, month(0) will get 1, so I guess month(4) will get 5, however I am not familiar with SQL, I could not give you correct answer. Could you give me some forum money? Thank you.   

藤椅
astrozscore 发表于 2012-7-20 12:21:54
好难的code.

板凳
jasonscut 在职认证  发表于 2012-7-20 12:37:25

我们经常用的netezza SQL里面没有这种month  function, 而是用这个

date_part('month' , a.saledate) as month.

北美统计金融博士

报纸
BraveMadMan 发表于 2012-7-20 15:24:55
能不能发更完整的code。没有上下文,很难理解吧
Don't get lost in technical details. What is the big picture?

地板
情迷仲夏夜 发表于 2012-7-21 03:46:38
the complete SQL code could be like the followings, but the problem is the SAS does not have a function called cast() yet, even in SAS v9.3, so it still can't make LZ's idea work, so what does the "cast((date1+2 - date2 month(4) as int)" mean? the word 'cast' means convert and it can convert int2char or char2int or something similar! and also month('03Apr2001'd)=4, but month(4)=1, even month(0)=1 in SAS, so cast((date1+2 - date2 month(4) as int) is not valid statement for proc SQL in SAS.
  1. proc sql;
  2.     connect to database (blah blah);
  3.     create table sas_dataset as
  4.     select * from connection to database(
  5.        select cast(bigint_var as integer), varchar_var, char_var,
  6.        from some_table);
  7.     disconnect from database;
  8. quit;
  9. or
  10. proc sql;
  11.     connect to database (blah blah);
  12.     create table sas_dataset as
  13.     select * from connection to database(
  14.        select cast((date1+2 - date2 month(4) as int), varchar_var, char_var,
  15.        from some_table);
  16.     disconnect from database;
  17. quit;
复制代码

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-26 15:51