SAS 9.3 DATETIME可变格式作为日期 [英] SAS 9.3 DATETIME VARIABLE FORMAT AS DATE

查看:1701
本文介绍了SAS 9.3 DATETIME可变格式作为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datetime22.3变量,我想显示为日期。

I have a datetime22.3 variable which I would like to display as date.

例如我想显示17JUL2006:00:00:00.000 as 07 / 17/2006

for eg I want to display 17JUL2006:00:00:00.000 as 07/17/2006

我该怎么做?

谢谢。

附加信息:

感谢所有答复。

我正在尝试以下列方式使用INTCK,但会收到错误。我不知道我在做错什么我很感激你的帮助谢谢。

I am trying to use INTCK in the following manner but get error. I am not sure what I am doing wrong. I would appreciate your help. Thanks.

PROC FORMAT;
PICTURE DTFMT LOW-HIGH='%0m/%0d/%Y'  (DATATYPE=DATETIME);
RUN;

data want;
dt_val1='17JUL2006:00:00:00.000'dt;
dt_val2='17AUG2012:00:00:00.000'dt;
format dt_val1 dt_val2 dt_val3 dtfmt.;
dt_val3=intck('MONTH',dt_val1,dt_val2);
put dt_val3;
run; 


推荐答案

您不能直接对标准日期格式一个datetime值,虽然有一些日期格式,您可以使用'DT'前缀,将显示一个日期时间作为日期。不幸的是,MMDDYY格式不是其中之一,但是您可以使用DTDATE9。这将格式化您的日期时间为'17JUL2006'。

You can't apply a standard date format directly against a datetime value, although there are some date formats you can prefix with 'DT' which will display a datetime as a date. Unfortunately the MMDDYY format is not one of these, however you could use DTDATE9. which would format your datetime as '17JUL2006'.

另一个选项是使用PICTURE语句创建自己的格式,下面的示例将根据需要显示datetime。 >

Another option is create your own format using the PICTURE statement, the example below will display the datetime as required.

proc format;
picture dtfmt low-high='%0m/%0d/%Y' (datatype=datetime);
run;

data want;
dt_val='17JUL2006:00:00:00.000'dt;
format dt_val dtfmt.;
run;

这篇关于SAS 9.3 DATETIME可变格式作为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆