我在SAS目錄上有大約27,000個.csv文件,這些文件也被複制到網絡驅動器中,因此我可以選擇使用其中一種。追加和編輯SAS中的多個CSV文件
我需要將所有csv文件合併到一個數據集並刪除任何空行(空列在A列中包含一個逗號)。
每個CSV文件都有唯一的名稱,但結構和格式是相同的。
在最後的數據集。我想A列包含的數據從導入文件範圍A1被複制的文件名:到S1:下到B列到T
我已經試過下面的代碼,但它圍繞後1000文件失敗:
x 'cd C:\temp';
filename csv ('*.csv');
proc import out=work.LSPImportFiles
datafile = csv DBMS=CSV REPLACE;
GETNAMES=yes;
run;
我也嘗試下面的代碼,但這似乎錯過列8,9和後幾百年失敗:
data want;
length _filename_ $32;
infile C:\temp\*.csv" dlm = ',' filename = _filename_;
input @;
if _filename_ ne lag1(_filename_) then delete;
input
Column_1 :$15.
Column_2 :$16.
Column_3 /*this is a number to 2 decimal places*/
Column_4 /*this is a number to 2 decimal places*/
Column_5 /*this is a number to 2 decimal places*/
Column_6 /*this is a number to 2 decimal places*/
Column_7 /*this is a number to 2 decimal places*/
Column_8 /*this is a percentage*/
Column_9 /*this is a percentage*/
Column_10 /*this is a number to 2 decimal places*/
Column_11 /*this is a number to 2 decimal places*/
Column_12 /*this is a number to 2 decimal places*/
Column_13 /*this is a number to 2 decimal places*/
Column_14 /*this is a blank column*/
Column_15 /*this is a number to 2 decimal places*/
Column_16 /*this is a number to 2 decimal places*/
Column_17 /*this is a number to 2 decimal places*/
run;
如果第8和第9列有百分號,那麼您應該使用PERCENT格式或COMMA。我還會包括INFILE語句選項DSD和MISSOVER。最好從數據步驟中看到日誌記錄,至少與數據錯誤和新行相關的日誌記錄。我不需要看27000個「INFILE IS」筆記。我懷疑你有流水和其他「問題」。 –
「失敗」是什麼意思? – Joe