全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1480 0
2014-11-10
data dup;
   length key date1 date2 8;
   input key  date1 date2 ;
   datalines;
1    0  3
1  4  7
2  1  2
3  3  4
3  7  9
3  10 11
   ;

proc print;run;

data test;
  do i=1 to 20;
     key=ceil(5*ranuni(123));
     purchase_date=ceil(10*ranuni(123));
     output;
  end;
run;

proc print;run;

data test2;

if _N_=1 then do;

   dcl hash h(dataset:'dup', multidata: 'y');
   h.definekey('key');
   h.definedata('key', 'date1', 'date2');
   h.definedone();

end;

   /* avoid uninitialized variable notes */
   call missing (key, date1, date2 );


   set test;

      rc = h.find();
      find=0;
      if (rc = 0) then do;
           if date1<=purchase_date<=date2 then do;
            key2=catx('#',key, put(date1,date9.),  put(date2,date9.));
            output;
            find=1;
           end;

           rc = h.find_next();
           do while(rc = 0);
            if find=1 then leave;
            if date1<=purchase_date<=date1 then do;
              key2=catx('#',key, put(date1,date9.),  put(date2,date9.));
              find=1;
              output;
            end;
            rc = h.find_next();
          end;
         
          if find=0 then do;
             remark='out of date range';
             output;
          end;

      end;

      else do;
        key2='ERROR';
         output ;
        end;
   
run;

proc print;run;


二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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