我想从 SAS 中的日期时间格式列中提取月份数据 [英] I want to extract month data from a datetime format column in SAS

查看:150
本文介绍了我想从 SAS 中的日期时间格式列中提取月份数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个格式为 01 Jan 19.00.00(日期时间)的数据,我只想从中提取月份名称.

I have a data in format 01 Jan 19.00.00 (datetime), and I want to extract the month name only from it.

尝试了下面的代码,但得到的输出是数字,即 1 2 3 等等.我想要一月二月三月格式或一月二月三月格式的输出.

Tried the below code but getting output in numbers i.e. 1 2 3 and so on. I want the output either in Jan Feb mar format or January February march format.

data want;
  set detail;
  month = month(datepart(BEGIN_DATE_TIME));
run;

推荐答案

如果您在报告中使用该值,更好的方法可能是使用用 MONNAME 格式化的日期值.

If you are using the value in a report the better approach might be to use a date value formatted with MONNAME.

当变量用于CLASSBY 语句时,日期格式变量的值将被正确排序.如果您改为计算一个新变量作为月份名称,则值的默认顺序将按字母顺序排列.

The values of a date formatted variable will be ordered properly when the variable is used in a CLASS or BY statement. If you had instead computed a new variable as the month name, the default ordering of values would be alphabetical.

data want;
  set have;
  begin_date = datepart(BEGIN_DATE_TIME);
  format begin_date MONNAME3.;
run;

这篇关于我想从 SAS 中的日期时间格式列中提取月份数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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