Sas 填写日期范围内的月份和年份?
我是SAS的新手,想知道除了开始日期和结束日期之外,如何最有效地列出介于开始日期和结束日期之间的月份和年份。我已经读过关于INTCK和INTNX函数,时间序列数据的扩展函数,甚至日历填充,但我不知道如何将它们用于这个特殊目的。由于具有下拉自动填充功能,使用Excel中的小数据集手动完成此任务很容易,但由于数据集的大小,我需要在SAS中找到一种方法来完成此任务。如有任何建议,将不胜感激。谢谢大家! 数据集位于一个大的文本文件中,组织方式如下:Sas 填写日期范围内的月份和年份?,sas,time-series,Sas,Time Series,我是SAS的新手,想知道除了开始日期和结束日期之外,如何最有效地列出介于开始日期和结束日期之间的月份和年份。我已经读过关于INTCK和INTNX函数,时间序列数据的扩展函数,甚至日历填充,但我不知道如何将它们用于这个特殊目的。由于具有下拉自动填充功能,使用Excel中的小数据集手动完成此任务很容易,但由于数据集的大小,我需要在SAS中找到一种方法来完成此任务。如有任何建议,将不胜感激。谢谢大家! 数据集位于一个大的文本文件中,组织方式如下: ID Start
ID Start End
1000 08/01/2012 12/31/2012
1001 07/01/2010 05/31/2011
1002 04/01/1990 10/31/1991
但最终的输出应该是这样的:
ID MonthYear
1000 08/12
1000 09/12
1000 10/12
1000 11/12
1000 12/12
1001 07/10
1001 08/10
1001 09/10
1001 10/10
1001 11/10
1001 12/10
1001 01/11
1001 02/11
1001 03/11
1001 04/11
1001 05/11
1002 04/90
1002 05/90
1002 06/90
1002 07/90
1002 08/90
1002 09/90
1002 10/90
1002 11/90
1002 12/90
1002 01/91
1002 02/91
1002 03/91
1002 04/91
1002 05/91
1002 06/91
1002 07/91
1002 08/91
1002 09/91
1002 10/91
这样就行了。PROC EXPAND可能更有效,尽管我认为它需要大量的期望观察,而不是一个开始/结束的组合,尽管我想你可以做到这一点
data have;
informat start end MMDDYY10.;
input ID Start End;
datalines;
1000 08/01/2012 12/31/2012
1001 07/01/2010 05/31/2011
1002 04/01/1990 10/31/1991
;;;;
run;
data want;
set have;
format monthyear MMYYS5.; *formats the numeric monthyear variable with your desired format;
monthyear=start; *start with the initial observation;
output; *output it;
do _t = 1 by 1 until (month(monthyear)=month(end)); *iterate until end;
monthyear = intnx('month',monthyear,1,'b'); *go to the next start of month;
output; *output it;
end;
run;
这样就行了。PROC EXPAND可能更有效,尽管我认为它需要大量的期望观察,而不是一个开始/结束的组合,尽管我想你可以做到这一点
data have;
informat start end MMDDYY10.;
input ID Start End;
datalines;
1000 08/01/2012 12/31/2012
1001 07/01/2010 05/31/2011
1002 04/01/1990 10/31/1991
;;;;
run;
data want;
set have;
format monthyear MMYYS5.; *formats the numeric monthyear variable with your desired format;
monthyear=start; *start with the initial observation;
output; *output it;
do _t = 1 by 1 until (month(monthyear)=month(end)); *iterate until end;
monthyear = intnx('month',monthyear,1,'b'); *go to the next start of month;
output; *output it;
end;
run;
这也行,非常感谢你,乔!这个解释很有帮助。这也很有效,非常感谢你,@Joe!这个解释很有帮助。