我正在浏览一堆按日历年和其他变量划分的文件。我想做的是按财政年度对它们进行分区(基于记录中存在的日期变量)。例如,要创建 FY2010 文件,我需要堆叠 CY2009 和 CY2010 文件(我们将这些文件称为 file_2009 和 file_2010)和 FY2010 记录的子集。但是,其中一个或两个文件可能不存在。我想要做的是,如果其中一个文件不存在,那么只需使用另一个文件。如果两者都退出,则同时使用。否则,什么也不做。我想出的方法没有我想要的那么紧凑。关于这样做的最佳方式的任何想法?谢谢。
问问题
75 次
1 回答
1
我将把拆分逻辑留给你 - 正如其他人所评论的那样,这在 SAS 中很少是一个好主意,因为通过按组处理来实现相同的结果几乎总是更简单。
这是我能想到的用于合并文件的最简单方法。
/*First, generate some dummy data*/
data cy2002 cy2004 cy2005;
do year = 2002,2004, 2005;
do _n_ = 1 to 10;
date =mdy(ceil(ranuni(1)*12),1,year);
format date yymmdd10.;
if year = 2002 then output cy2002;
if year = 2004 then output cy2004;
if year = 2005 then output cy2005;
end;
end;
run;
/*
Generate a listing of all sas datasets in the appropriate library.
For simplicity, assume these are sequentially named and are the only datasets in the library.
*/
ods listing close;
ods output members = members;
proc datasets lib = work memtype=data;
run;
quit;
ods listing;
/*Use the listing dataset to create a view that pieces together all of the calendar year datasets*/
data _null_;
set members end = eof;
if _n_ = 1 then call execute('data combined /view = combined; set ');
call execute(name);
if eof then call execute('; run;');
run;
然后,您可以使用该视图根据日期计算财政年度,并将其用于任何需要的进一步处理。
于 2015-05-08T14:34:51.990 回答