由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - Help needed! What sas function can read char. date HH:DD:SS:SSS to numeric?
相关主题
问一个SAS的问题,急急!!请教一个sas的sort date变量问题
SAS菜鸟请教substr想用first累计character的变量,可以吗?
问一个sas format问题请教个 SAS 读数据的问题
怎样在data step跳过格式不对的data record?sas 变量赋值问题
SAS format 的问题base 123题第72/73题求解:关于substr的返回长度
如何根据cdf(比较复杂,不能求微分)求其pdfsas help!!
Help! sas macro qeustions.SAS里关于recode一问
sas一问一个很疑惑的SAS日期问题
相关话题的讨论汇总
话题: format话题: date话题: function话题: what话题: 30sep2011
进入Statistics版参与讨论
1 (共1页)
B********9
发帖数: 44
1
Hey, please help! Thanks in advance!
I have a character date eg: 30SEP2011:10:12:31:705. I need read this char.
date to numeric, format as datetime22.3. What function I can use it?
I know there is a function called DHMS, but only read till HH:DD:SS level,
not to HH:DD:SS:SSS.
I'm waiting on-line to see if anyone know the answer.Thanks for your kindly
helps.
g*****d
发帖数: 526
2
没明白,你是想读入呢,还是想转换呢?
B********9
发帖数: 44
3
Right, this is format. I wonder whether we have SAS function to read this
char. date while the format is numeric with datetime22.3.
EX: we can use DHMS function to read char. date and reformat as a numeric
date as date22.3, however, the last SSS will be the default as "000".
Thanks.
g*****d
发帖数: 526
4
看看这是你要的意思么?
data a;
x='30SEP2011:10:12:31:705';
y=input(x,date22.3);
run;
B********9
发帖数: 44
5
Okay, let be clear on this.
I have a character date 30SEP2011:10:12:31:705 format as $30. I need to read
this date first as character. And then reformat this date to numeric and
format as datetime22.3.
What SAS function can do such converting and reformatting? Thanks
B********9
发帖数: 44
6
Thanks, however, this is not working. This will return missing value on y.

【在 g*****d 的大作中提到】
: 看看这是你要的意思么?
: data a;
: x='30SEP2011:10:12:31:705';
: y=input(x,date22.3);
: run;

g*****d
发帖数: 526
7
哦,我写错format了。
应该是
data a;
x='30SEP2011:10:12:31.705';
y=input(x,datetime22.);
format y datetime22.3;
run;

【在 B********9 的大作中提到】
: Thanks, however, this is not working. This will return missing value on y.
g*****d
发帖数: 526
8
你需要把最后一个“:"改成".",
然后input吧
B********9
发帖数: 44
9
Yes, that's right, it's my typing mistake, sorry~
The input function is not working. Because if we use "input" function to
reformat a char date, the result only return sas date format, which is not
what I want.
In your case: Y=input(X,datetime22.3):
X: 30SEP2011:10:12:31.705 type: Char; length: 22
Y: 1632996751.7 type: Num; Length:8
However, this is what I want:
Y: 30SEP2011:10:12:31.705 type: Num; length: 8; informat: Datetime22.3;
format: Datetime22.3.
Any suggestions? Thanks

【在 g*****d 的大作中提到】
: 你需要把最后一个“:"改成".",
: 然后input吧

g*****d
发帖数: 526
10
。。。
干嘛这么在意informat?
g*****d
发帖数: 526
11
实在想要informat,你只能开始就定义y,然后再input吧。
B********9
发帖数: 44
12
This is a requested format we need to create for comparison with other
tables. So have to be exactly same.Thanks

【在 g*****d 的大作中提到】
: 。。。
: 干嘛这么在意informat?

g*****d
发帖数: 526
13
那就提前定义好y呗。
data a;
informat y datetime22.3;
x='30SEP2011:10:12:31.705';
y=input(x,datetime22.);
format y datetime22.3;
run;
只是个大概意思,下班了,家里没sas,不能测试了。

【在 B********9 的大作中提到】
: This is a requested format we need to create for comparison with other
: tables. So have to be exactly same.Thanks

B********9
发帖数: 44
14
Thank you for your help, I got my answer today. :-)
Y=DHMS(input(substr(x,1,10),yymmdd10.),substr(x,11,2),substr(x,14,2),substr
(x,17,6));
Of course, we need to length, format and informat before the function.
The reason why I failed yesterday because under the last substr for seconds,
I only included 2 not 6 (substr(x,17,2). Therefore, I didn't included
million second into the new file.

【在 g*****d 的大作中提到】
: 那就提前定义好y呗。
: data a;
: informat y datetime22.3;
: x='30SEP2011:10:12:31.705';
: y=input(x,datetime22.);
: format y datetime22.3;
: run;
: 只是个大概意思,下班了,家里没sas,不能测试了。

1 (共1页)
进入Statistics版参与讨论
相关主题
一个很疑惑的SAS日期问题SAS format 的问题
求教SAS问题如何根据cdf(比较复杂,不能求微分)求其pdf
SAS data merge求助Help! sas macro qeustions.
help how to convert char to numeric variable?sas一问
问一个SAS的问题,急急!!请教一个sas的sort date变量问题
SAS菜鸟请教substr想用first累计character的变量,可以吗?
问一个sas format问题请教个 SAS 读数据的问题
怎样在data step跳过格式不对的data record?sas 变量赋值问题
相关话题的讨论汇总
话题: format话题: date话题: function话题: what话题: 30sep2011