删除具有特定格式的日期列观察

时间:2016-12-22 12:14:36

标签: sas

我正在尝试从DM数据集中删除所有日期列BRTHDTC DMDTC RFENDTC RFSTDTC观察值,该数据集位于我的用户定义库YYMMDD10. format中。

proc sql noprint;
    select distinct catx(".",libname,memname), name into :dtelist separated by " ", :dtevars separated by " "
    from dictionary.columns
    where libname = upcase("Dtelib") and format =('YYMMDD10.');
quit;

data drpdte(Keep=&dtevars);
set &dtelist;
if &dtevars =('&dtevars'd,YYMMDD10.) then delete;
run;

但它返回多个参数的错误,任何帮助都表示赞赏。

1 个答案:

答案 0 :(得分:2)

下面应该适合你。我输出proc contents然后将格式变量串在一起,这样你就可以得到所有变量及其格式的列表。然后你可以把它放到一个宏中并在drop语句中使用它:

** test data **;
data test;
    bad_date = "05OCT2016"D;
    good_date = "12DEC2016"D;
    good_date1 = "22DEC2016"D;
    car = "Ford";
    model = "F-150";
    format bad_date yymmdd10. good_date yymmdd9. good_date1 date10.;
run;

** view list of variables and their formats **;
proc contents data = test noprint out=names; run;

** string together format and length to view YYMMDD10 **;
data names1; set names;
    new_format = compress(catx("",format,formatl));
    keep name new_format;
run;

** put the YYMMDD10 vars into a macro variable **;
proc sql noprint;
    select name
    into: dropvars separated by " "
    from names1
    where new_format = "YYMMDD10";
quit;

%put &dropvars.;

data test1; set test (drop=&dropvars.); run;