SAS 9.3 日期时间变量格式为日期 [英] SAS 9.3 DATETIME VARIABLE FORMAT AS DATE

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

问题描述

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

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

例如,我想将 17JUL2006:00:00:00.000 显示为 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; 

推荐答案

您不能将标准日期格式直接应用于日期时间值,尽管有些日期格式可以使用 '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 语句创建您自己的格式,下面的示例将根据需要显示日期时间.

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 日期时间变量格式为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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