我有一个类似下面的数据集,我想知道如何填写SAS中缺少的日期。
缺少FROM_NEW(第2行)
首先,在同一ADM下的TOS =“FAC_IP”的最后一行找到TO_NEW(14NOV2016)。 然后,在PRO_IP中循环以找到min(日期)但大于(> 14NOV2016)以替换缺少的 20NOV2016 的FROM_NEW。
缺少TO_NEW(第25行)
首先,在TOS =“FAC_IP”的最后一行找到FROM_NEW(14DEC2016)
然后,在PRO_IP中循环以找到最大(日期)但小于(< 14DEC2016)以替换应填写 08DEC2016 的缺失的TO_NEW。
Obs MEMNUM ADM LINE FROM TO FROM_NEW TO_NEW TOS order
1 9840964190000001 237696870 X 23OCT2016 23NOV2016 23OCT2016 30OCT2016 FAC_IP 1
2 9840964190000001 237696870 R 23OCT2016 23NOV2016 . 23NOV2016 FAC_IP 2
3 9840964190000001 237696870 X 23OCT2016 23NOV2016 02NOV2016 03NOV2016 FAC_IP 3
4 9840964190000001 237696870 X 23OCT2016 23NOV2016 05NOV2016 09NOV2016 FAC_IP 4
5 9840964190000001 237696870 X 23OCT2016 23NOV2016 11NOV2016 14NOV2016 FAC_IP 5
6 9840964190000001 237696870 23OCT2016 23NOV2016 25OCT2016 25OCT2016 PRO_IP .
7 9840964190000001 237696870 23OCT2016 23NOV2016 26OCT2016 26OCT2016 PRO_IP .
8 9840964190000001 237696870 23OCT2016 23NOV2016 27OCT2016 27OCT2016 PRO_IP .
9 9840964190000001 237696870 23OCT2016 23NOV2016 28OCT2016 28OCT2016 PRO_IP .
10 9840964190000001 237696870 23OCT2016 23NOV2016 29OCT2016 29OCT2016 PRO_IP .
11 9840964190000001 237696870 23OCT2016 23NOV2016 30OCT2016 30OCT2016 PRO_IP .
12 9840964190000001 237696870 23OCT2016 23NOV2016 02NOV2016 02NOV2016 PRO_IP .
13 9840964190000001 237696870 23OCT2016 23NOV2016 03NOV2016 03NOV2016 PRO_IP .
14 9840964190000001 237696870 23OCT2016 23NOV2016 06NOV2016 06NOV2016 PRO_IP .
15 9840964190000001 237696870 23OCT2016 23NOV2016 07NOV2016 07NOV2016 PRO_IP .
16 9840964190000001 237696870 23OCT2016 23NOV2016 08NOV2016 08NOV2016 PRO_IP .
17 9840964190000001 237696870 23OCT2016 23NOV2016 11NOV2016 11NOV2016 PRO_IP .
18 9840964190000001 237696870 23OCT2016 23NOV2016 12NOV2016 12NOV2016 PRO_IP .
19 9840964190000001 237696870 23OCT2016 23NOV2016 13NOV2016 13NOV2016 PRO_IP .
20 9840964190000001 237696870 23OCT2016 23NOV2016 14NOV2016 14NOV2016 PRO_IP .
21 9840964190000001 237696870 23OCT2016 23NOV2016 20NOV2016 20NOV2016 PRO_IP .
22 9840964190000001 237696870 23OCT2016 23NOV2016 21NOV2016 21NOV2016 PRO_IP .
23 9840964190000001 237696870 23OCT2016 23NOV2016 22NOV2016 22NOV2016 PRO_IP .
24 9840964190000001 237696870 23OCT2016 23NOV2016 23NOV2016 23NOV2016 PRO_IP .
25 9840964190000001 244243815 R 04DEC2016 17DEC2016 04DEC2016 . FAC_IP 1
26 9840964190000001 244243815 X 04DEC2016 17DEC2016 14DEC2016 17DEC2016 FAC_IP 2
27 9840964190000001 244243815 04DEC2016 17DEC2016 04DEC2016 04DEC2016 PRO_IP .
28 9840964190000001 244243815 04DEC2016 17DEC2016 05DEC2016 05DEC2016 PRO_IP .
29 9840964190000001 244243815 04DEC2016 17DEC2016 06DEC2016 06DEC2016 PRO_IP .
30 9840964190000001 244243815 04DEC2016 17DEC2016 07DEC2016 07DEC2016 PRO_IP .
31 9840964190000001 244243815 04DEC2016 17DEC2016 08DEC2016 08DEC2016 PRO_IP .
32 9840964190000001 244243815 04DEC2016 17DEC2016 14DEC2016 14DEC2016 PRO_IP .
33 9840964190000001 244243815 04DEC2016 17DEC2016 15DEC2016 15DEC2016 PRO_IP .
34 9840964190000001 244243815 04DEC2016 17DEC2016 16DEC2016 16DEC2016 PRO_IP .
35 9840964190000001 244243815 04DEC2016 17DEC2016 17DEC2016 17DEC2016 PRO_IP .
答案 0 :(得分:0)
所以,这里是如何在sas宏中更新FROM_NEW的。它很明确,您应该能够创建自己的宏来执行TO_NEW。如果您需要其他帮助,请回复您尝试过的内容,我们可以从那里开始。确保所有日期都是实际的sas日期,而不是数据集中的文字
*create file of all needed from_new dates
proc sql noprint;
create table needed_FN as
select distinct adm,order as row from test where from_new = .;quit;
* find out how many we have
proc sql noprint;
select count(*) into: cnt from needed_fn;quit;
*create macro to loop through
%macro test;
%do i = 1 %to &cnt;
*for each needed from_new date place the adm and order number into macro vars
proc sql noprint;
select ADM,row into: adm, :row from needed_FN where monotonic()=&i;quit;
* create temp table for specific adm
proc sql noprint;
create table work as
select * from test where adm = &adm;quit;
* find out how many 'FAC_IP's we have
proc sql noprint;
select max(order)into:maxOrder from work;quit;
* get the checkdate
proc sql noprint;
select (TO_NEW) format=date9. into:checkDate from work where ORDER= &maxOrder;
*create temp table of all PRO_iP dates > checkDate
proc sql noprint;
create table proDates as
select * from work where TOS='PRO_IP' and FROM_NEW > "&checkDate"d;quit;
* get the smallest one
proc sql noprint;
select min(From_new)format date9. into:replaceDate from prodates;quit;
*update the table
proc sql;
update test
set from_new = "&replaceDate"d
where adm = &adm
and order = &row;
%end;
%mend test;
%test;
答案 1 :(得分:0)