Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 将YYMM编号转换为日期以计算SAS中的月间隔_Date_Sas_Formatting - Fatal编程技术网

Date 将YYMM编号转换为日期以计算SAS中的月间隔

Date 将YYMM编号转换为日期以计算SAS中的月间隔,date,sas,formatting,Date,Sas,Formatting,我是SAS的新手,我有以下问题。我使用的数据库在两列中有两个日期,我应该在几个月内计算两者之间的差异 这些日期的格式为YYMM,例如:200603为2006年3月,200612为2006年12月。 两者之间的差异应为9个月 我正在尝试创建一个新的列(称为“difference”),其中包含日期差异。我尝试了以下代码: data TIMES.TEST; set TIMES.INPUTS; difference = intck('month',input(fin_period,yymmn6.

我是SAS的新手,我有以下问题。我使用的数据库在两列中有两个日期,我应该在几个月内计算两者之间的差异

这些日期的格式为YYMM,例如:200603为2006年3月,200612为2006年12月。 两者之间的差异应为9个月

我正在尝试创建一个新的列(称为“difference”),其中包含日期差异。我尝试了以下代码:

data TIMES.TEST;
set TIMES.INPUTS;    
difference = intck('month',input(fin_period,yymmn6.),input(period,yymmn6.));
run;
它创建了一个名为difference(correct)的新列,但该列全部用点填充。什么都不算。我做错什么了吗?当我有这样的日期格式时,有没有其他方法来计算两个日期之间的差异

提前谢谢


我使用SAS Studio。

如果
period
fin_period
存储为数字变量,则需要将它们转换为文本,然后才能应用
yymmn6.
信息将它们转换为日期

以下是一些可能有助于使这一点更清楚的示例:

data inputs;
input period fin_period;
cards;
200603 200612
;
run;

/*Difference = .*/
data test;
set inputs;    
difference = intck('month',input(fin_period,yymmn6.),input(period,yymmn6.));
run;

data inputs2;
input period $ fin_period $;
cards;
200603 200612
;  
run;

/*Difference = -9*/
data test2;
set inputs2;    
difference = intck('month',input(fin_period,yymmn6.),input(period,yymmn6.));
run;

/*Difference = -9*/
data test3;
set inputs;    
difference = intck('month',input(put(fin_period,6.),yymmn6.),input(put(period,6.),yymmn6.));
run;

哇!感谢您的快速回复。你提出的代码非常有效。非常感谢。