使用retain变量将帮助您实现此目的。
使用下面的代码,只需使用文件名替换infile
语句中的datalines
并设置正确的infile
参数。
data rawImport;
infile datalines dsd delimiter=' ' truncover;
informat C1-C4 $32.;
input C1-C4;
datalines;
Earnings
abc 123 xyz abjjdd
bhb edw ajd jnjnjknn
ebc ecc cec cecekckk
Redemptions
abc 234 xyz abjjdd
bhb edw ajd jnjnjknn
ebc ecc cec cecekckk
Expirations
abc 345 xyz abjjdd
bhb edw ajd jnjnjknn
ebc ecc cec cecd ccsdc
djc c djc cjdcjjnc
;
通过使用retain变量,我们现在可以将行调度到适当的数据集。
data Earnings Redemptions Expirations;
set rawImport;
length outputDS $ 12;
retain outputDS;
* Determine output dataset;
if C1 = "Earnings" then do;
outputDS = "Earnings";
delete;
end;
else if C1 = "Redemptions" then do;
outputDS = "Redemptions";
delete;
end;
else if C1 = "Expirations" then do;
outputDS = "Expirations";
delete;
end;
* output to appropriate dataset;
if outputDS = "Earnings" then output Earnings;
else if outputDS = "Redemptions" then output Redemptions;
else if outputDS = "Expirations" then output Expirations;
drop outputDS;
run;
日志现在显示:
NOTE: There were 13 observations read from the data set WORK.RAWIMPORT.
NOTE: The data set WORK.EARNINGS has 3 observations and 4 variables.
NOTE: The data set WORK.REDEMPTIONS has 3 observations and 4 variables.
NOTE: The data set WORK.EXPIRATIONS has 4 observations and 4 variables.