You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为保单生效周期内的各月份生成13个月度激活标识flag

SAS实现保单月度激活标识生成方案

步骤1:预处理逻辑说明

首先对原始数据做基础处理:

  • 将字符型的起止日期字段转换为SAS标准日期格式
  • 缺失的policy_end_date默认取policy_beg_date加14个月的月末日期(刚好覆盖0~13月的计算范围,可按需调整边界)
  • 计算保单生效起始月份month_begining、保单覆盖的最终月份month_end,格式统一为YYYYMM数值型

步骤2:实现代码

data policy_result;
    input policy $ policy_beg_str $ policy_end_str $;
    /* 字符日期转SAS日期格式 */
    policy_beg_date = input(policy_beg_str, ddmmyy10.);
    if not missing(policy_end_str) then policy_end_date = input(policy_end_str, ddmmyy10.);
    /* 缺失终止日期的保单默认覆盖13个月计算区间 */
    else policy_end_date = intnx('month', policy_beg_date, 14, 'end');
    format policy_beg_date policy_end_date ddmmyyn10.;

    /* 生成月份边界字段 */
    month_begining = input(put(intnx('month', policy_beg_date, 0, 'b'), yymmn6.), 6.);
    month_end = input(put(intnx('month', policy_end_date, 0, 'e'), yymmn6.), 6.);

    /* 批量生成0~13月激活标识 */
    array act_flag[0:13] flag_0month flag_1month flag_2month flag_3month flag_4month flag_5month flag_6month flag_7month flag_8month flag_9month flag_10month flag_11month flag_12month flag_13month;
    do offset = 0 to 13;
        current_cal_month = input(put(intnx('month', policy_beg_date, offset, 'b'), yymmn6.), 6.);
        if current_cal_month >= month_begining and current_cal_month <= month_end then act_flag[offset] = 1;
        else act_flag[offset] = .; /* 若不需要空值可改为赋值0 */
    end;

    drop offset policy_beg_str policy_end_str current_cal_month;
datalines;
a 01-01-2018 06-02-2018
b 04-02-2019 02-04-2020
c 23-12-2019 03-02-2020
d 02-02-2019 ''
;
run;

逻辑验证说明

  • 采用intnx函数做月份偏移,b参数取月初、e参数取月末,避免跨月日期判断出错
  • 数组批量处理标识字段,无需重复编写14次判断逻辑,扩展性强
  • 缺失终止日期的处理规则可按业务调整,如需统计到实际当前日期,可将缺失赋值逻辑改为policy_end_date = today()

内容的提问来源于stack exchange,提问作者user8419142

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 15:48:01