yyyymm转换为完整sas日期(dd / mm / ccyy) - SAS [英] yyyymm convert to full sas date (dd/mm/ccyy) - SAS
问题描述
我试图从SAS(ccyymm)中的字段数字中获取本月的最后一天。
I am trying to get the last day of the month from a field numeric in SAS (ccyymm).
例如
201401将是31- 01-2014。
for example 201401 would be 31-01-2014.
我已经设法使字段显示为一个日期类型字段(仍然显示为ccyymm),在PROC SQL SELECT语句中使用以下代码
I have managed to get the field to show as a date type field (still showing as ccyymm though) with the following code in a PROC SQL SELECT statement
year_month_field INFORMAT YYMMN6. AS year_month_date
我认为我发现另一个问题的代码,应该给我
I think that I found some code from another question that had been asked that should give me the last day of the month once I can get the full date.
INTNX ( MONTH , year_month_date , 1) -1
这个工作吗?如果没有任何其他建议将不胜感激。
Will this work? If not any other suggestions would be appreciated.
Dan
推荐答案
请注意,将yyyymm转换为MMMYYYY格式之间的差异,取决于yyyymm是字符还是数字变量。
Note the difference between how one would convert a yyyymm to "last day of the month"MMMYYYY format below, depending on whether yyyymm is character or numeric variable.
data test;
yyyymm_character='201401';
yyyymm_numeric=201401;
date1=intnx('month', input(yyyymm_character, yymmn6.), 1)-1;
date2=intnx('month', input(put(yyyymm_numeric,6.), yymmn6.), 1)-1;
format date1 date2 date9.;
/*date1=date2=31jan2014*/
run;
或者,您可以使用内置的选项 intnx
函数自动将输入日期设置为相应月份的最后一天。使用'e'
如下所示。
Alternatively, you can use the in-built options for intnx
functions to automatically set any input date to the last day of the respective month. Use 'e'
as shown below.
data test;
yyyymm_character='201401';
yyyymm_numeric=201401;
date1=intnx('month', input(yyyymm_character, yymmn6.), 0, 'e');
date2=intnx('month', input(put(yyyymm_numeric,6.), yymmn6.), 0,'e');
format date1 date2 date9.;
/*date1=date2=31jan2014*/
run
这篇关于yyyymm转换为完整sas日期(dd / mm / ccyy) - SAS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!