全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
6127 8
2013-03-20
悬赏 20 个论坛币 已解决
工作需要,要经常更新一些数据。但源数据中日期是不连续的,有断层。现在需要补齐缺失的日期,并且根据usid来生产序号。具体文件见附件。谢谢各位大神帮忙了。ps:只要能解决问题即可,不限定用SAS,EXCEL也可。
期望效果.xls
大小:(52.5 KB)

 马上下载



原文件.xls
大小:(377.5 KB)

 马上下载

最佳答案

bobguy 查看完整内容

This one is clear in logic. data have; input id date: yymmdd10.; format date yymmdd10.; cards; 1 2012-02-16 1 2012-02-17 1 2012-02-20 1 2012-03-01 1 2012-03-03 2 2012-02-20 2 2012-02-23 2 2012-02-24 2 2012-03-03 3 2012-03-01 3 2012-03-02 ; run; proc means data=have nway noprint; class id ; var date ; output out=minmax(keep=id min_dat ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-3-20 20:51:42
This one is clear in logic.

data have;
  input id date: yymmdd10.;
  format date yymmdd10.;
  cards;
  1  2012-02-16
  1  2012-02-17
  1  2012-02-20
  1  2012-03-01
  1  2012-03-03
  2  2012-02-20
  2  2012-02-23
  2  2012-02-24
  2  2012-03-03
  3  2012-03-01
  3  2012-03-02
;
run;

proc means data=have nway noprint;
class id ;
var date ;
output out=minmax(keep=id min_date max_date) min=min_date max=max_date;
run;

data template;
   set minmax;
   do date=min_date to max_date;
     output;
        end;
        format date yymmdd10.;
        drop min_date max_date;
run;

proc print;run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-21 01:26:47
I try to use fake data which is the same as your data  and apply the program to get the result you need.

data have;
  input id date: yymmdd10.;
  format date yymmdd10.;
  cards;
  1  2012-02-16
  1  2012-02-17
  1  2012-02-20
  1  2012-03-01
  1  2012-03-03
  2  2012-02-20
  2  2012-02-23
  2  2012-02-24
  2  2012-03-03
  3  2012-03-01
  3  2012-03-02
;
run;

data want(rename=(_date=date));
   set have;
   by id;
   retain  _date count_day;
   format _date yymmdd10.;
   if first.id then do;
      count_day=1;
          _date=date;
          output;
    end;
     else do;
               _date=intnx('day',_date,1);
                  if _date<date then do until (_date=date);
              count_day=count_day;
               output;
              _date=intnx('day',_date,1);
                       end;
                 if _date=date then do;
                                count_day+1;
                                output;
                             end;
     end;
drop date;
run;
proc print;
run;
            
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-21 08:34:04
用proc timeseries就可以解决
两三行就可以搞定
去官网搜下怎么写吧
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-22 09:52:18
In LZ' excel files, It seems that series  date without stop is needed to be produced, meanwhile a statistical variable for total days is also needed to be calculated.   
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-3-22 11:33:11
加一个用do loop 的方法。
The first row of the original excel file need to be changed
for sucessfull import.

假如你已经把excel数据import到 dataset: data0320.
变量名为 ID, DATE,DAYS,NUM
Try the following code.

proc sort data=data0320;
by ID date;
run;

data test_A;
     format date date_tmp yymmdd10.;
     retain date_tmp;
     set data0330;   
         by id;
         if first.id then  do;
                 date_tmp = date;
                 output;
                 end;
          interval = intck('day', date_tmp, date);
       if interval = 1 then do;
                     date_tmp = date;
                     output;
                     end;
       if interval > 1 then  do;
          do i = 1 to interval;
                     date_tmp = intnx('day', date_tmp, 1);
                     output;
          end;
       end;
     drop interval i days;
run;
data test_result (rename=(date_tmp=date));
      set test_a (drop=date);
          by id;
          if first.id then days=1;
          else days+1;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群