简体   繁体   English

SAS-从一个整数创建月份和年份日期

[英]SAS - Create a month and year date from one integer

I have a data set in which month and year are in one variable and come in the form 200801 which equates to 2008, January. 我有一个数据集,其中月份和年份是一个变量,格式为200801,等于2008年1月。 How can I create a SAS date from this integer? 如何从该整数创建SAS日期?

I would like something in the form of Jan 2008 - anything so that SAS recognizes it as a date, as I then need to subtract this value from service date to find out how much time has elapsed since enrollment into the dataset until date of service. 我想要某种形式的2008年1月的形式-以便SAS将其识别为日期,然后我需要从服务日期中减去该值,以找出自从注册到数据集到服务日期为止已经经过的时间。

Please also keep in mind that this is a variable, and I have thousands of observations. 还请记住,这是一个变量,我有成千上万的观察结果。 So I also need the data step/ function to do this for the entire variable. 因此,我还需要数据步骤/函数来为整个变量执行此操作。

Any help is appreciated! 任何帮助表示赞赏!

You need to put it to a character variable, then input back to numeric. 您需要将其放入字符变量,然后再输入回数字。 You can do that pretty easily. 您可以轻松地做到这一点。

date_var = input(put(date_var_orig,6.)||'01',yymmdd8.);

You can also do it this way: 您也可以这样操作:

date_var = mdy(mod(date_var_orig,100),1,floor(date_var_orig/100));

Both assume you want the day to equal 1; 两者都假设您希望当天等于1; make a choice there if you want something else (like end of month or middle of month). 如果您想要其他东西(例如月末或月中),请在此处进行选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM