2
我有以下的數據集,我需要從基於財政年度給出的日期(例如2013年4月至2014年3月)查找週數。例如01AprXXX,應該是一年的第0或第1周,明年3月的最後一週應該是52/53。我嘗試了一種方法來找出相同的結果(代碼也在下面)。如何根據SAS中的財政年度計算周價值?
I am just curious to know if there is any better way in SAS to do this in SAS
。提前致謝。請讓我知道這個問題是否是多餘的,在這種情況下,我會盡早刪除它,儘管我搜索了這個概念但沒有找到任何東西。
同樣我對我的英語表示歉意,可能在語法上不正確。但我希望我能夠表達我的觀點。
DATA
data dsn;
format date date9.;
input date date9.;
cards;
01Nov2015
08Sep2013
06Feb2011
09Mar2004
31Mar2009
01Apr2007
;
run;
CODE
data dsn2;
set dsn;
week_normal = week(date);
dat2 = input(compress("01Apr"||year(date)),date9.);
week_temp = week(dat2);
format dat2 date9.;
x1 = month(input(compress('01Jan'||(year(date)+1)),date9.)) ;***lower cutoff;
x2 = month(input(compress("31mar"||year(date)),date9.)); ***upper cutoff;
x3 = week(input(compress("31dec"||(year(date)-1)),date9.)); ***final week value for the previous year;
if month(dat2) <= month(date) <= month(input(compress("31dec"||year(date)),date9.)) then week_f = week(date) - week_temp;
else if x2 >= month(date) >= x1 then week_f = week_normal + x3 - week(input(compress("31mar"||(year(date)+1)),date9.)) ;
run;
RESULT
謝謝,我是埃格爾知道,如何改變這種間隔類型?請你可以指點我的文檔(如果它對你來說不是什麼大問題)。我很想了解它的概念謝謝 – PKumar
@KabirPradeep從[INTNX文檔]開始(http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000212700 .htm),然後一旦你明白了,請參閱[INTERVALDS = SYSTEM OPTION](http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003252593。 HTM)。 – Joe
非常感謝。 – PKumar