使用 SAS 转换格式(从日期到数字)
我正在使用 SAS 中的数据集,其中包含许多变量。
这些变量之一是 DATE 变量,它具有日期/时间格式。它看起来像这样:
12FEB97:00:00:00
27MAR97:00:00:00
14APR97:00:00:00
现在问题是我想将此变量转换为数字格式。我想得到以下结果(基于前面显示的 3 个示例):
199702
199703
199704
您有什么想法如何做到这一点吗?我已经阅读了许多文档、pdf 等,但仍然找不到合适的解决方案。
非常感谢!
I am working with a dataset in SAS, containing many variables.
One of these variables is a DATE variable and it has a date/time format. It looks like this:
12FEB97:00:00:00
27MAR97:00:00:00
14APR97:00:00:00
Now the thing is that I would like to convert this variable into a NUMERIC format. And I would like to get the following result (based on the previously shown 3 examples):
199702
199703
199704
Do you have any ideas how to do it? I already read through many docs, pdfs etc. but still could not find a proper solution yet.
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要从日期时间变量中提取日期。您可以使用
datepart
函数:然后,您希望将此变量(仍将编码为日期数字)转换为可以读取年份和月份的数字。使用 putn 执行此操作:
First, you need to extract the date from your datetime variable. You can use the
datepart
function:Then, you want to put this variable (which will still be coded as a date number) into a number that you can read the year and month. Do this with
putn
: