2016-12-22 46 views
0

我想刪除所有日期列BRTHDTC DMDTC RFENDTC RFSTDTC來自我的用戶定義庫中的DM數據集的觀測結果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; 

但它返回多個參數的錯誤,任何幫助表示讚賞。

+0

DELETE語句將消除觀察值,而不是變量。你的意思是生成一個DROP語句嗎? – Tom

+0

@Tom我想放下任何一列有yymmdd10。格式我想從我的數據中刪除該列。在我的情況下,這些列'BRTHDTC DMDTC RFENDTC RFSTDTC'應該從我的ds中刪除。 – user7108488

回答

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;