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 | | 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 | | 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,不能测试了。
|
|