将SAS日期转换为上周五结束的一周中的某一天

时间:2017-01-04 17:54:14

标签: sas

我正在试图操纵我的Dispensing_Date给我每个日期在上周五结束的一年的周末,这可以吗?这是我到目前为止所拥有的......

%let 1= 01012016;
%let 53 = 12302016;

**01 import whiteoak file;
proc import
    datafile = "E:\Horizon\Adhoc\AH\whiteoak.xlsx"
    out = whiteoak
    dbms = XLSX
    replace;
run;

** 02 remove dupes to ensure unique rx and fill;
proc sort nodup data=whiteoak;
by Rx_ Refill;
run;

** 03 Filter out holds;
data whiteoak;
set whiteoak;
where (Filled_Status="YES");
run;

** 04 create weekday variable;
data dates;
set whiteoak;
format Dispensing_Date MMDDYY8.;
run;

2 个答案:

答案 0 :(得分:0)

这是我对你问的最佳猜测。

24         data _null_;
25            x = today();
26            d = intnx('week.7',x,-1,'end');
27            put (_all_)(=weekdate.);
28            run;

x=Wednesday, January 4, 2017 d=Friday, December 30, 2016

答案 1 :(得分:0)

这样做你想要的吗?

data weeks;
  do date = '22DEC2016'd to '15JAN2017'd;
    format date first_friday weekdate.;
    sas_week=week(date);
    first_friday= intnx('week.7',intnx('year',date,0,'b'),0,'e');
    friday_week=1+int((7+date-first_friday)/7) ;
    output;
  end;
run;

如果有,则将其应用于您的数据:

data dates;
  set whiteoak;
  week = 1 + int((7+Dispensing_Date
       - intnx('week.7',intnx('year',Dispensing_Date,0,'b'),0,'e'))/7);
run;