在给定特定条件的情况下从表中删除行



我有下表"HAVE":

ID 日期
Test_5000_ABC_2022-01 2020年5月1日
测试_12345_XYZ_2022-05 2021年10月15日
测试00000_UMX_2022-12 2021年9月1日
测试00000_UMX_2022-12 2022年12月1日
  • 从ID变量中提取日期
  • 将日期与月初对齐
  • 根据需要进行比较
data have;
infile cards dlm='09'x truncover;
input ID : $23. Date : date9.;
cards;
Test_5000_ABC_2022-01   01MAY2020
Test_12345_XYZ_2022-05  15OCT2021
Test_00000_UMX_2022-12  01SEP2021
Test_00000_UMX_2022-12  01DEC2022
;;;;
run;
data want;
set have;
date_id = mdy(input(scan(id, -1, "-_"), 8.) , 1, input(scan(id, -2, "-_"), 8.) );
*check your condition;
if date_id > intnx('month', date, 0, 'b') then flag=1;
*if date_id > intnx('month', date, 0, 'b') then delete;
format date_id date yymmdds10.;
run;

您可以在proc sqlDATA步骤中使用以下条件:

where input(scan(ID, -1, '_')||'-01', yyyymmdd10.) > Date

scan取最后一个_之后的ID中的分数,没有训练空白。input将信息yyyymmdd10.应用于它。

最新更新