【发布时间】:2015-07-08 15:39:23
【问题描述】:
以前的帖子:
Variable check and summary out
Macro that outputs table with testing results of SAS table
问题/问题
从之前的帖子中,我认为我能够运行宏并产生所需的结果。但是,在最终收到输出无法正常工作的报告后,我真的很困惑为什么我会收到缺少变量的错误。看起来好像数据集在子设置后没有被加载。我能够处理基本的汇总统计表,但是当我加载宏时,输出不起作用。
为什么数据集没有加载?宏是否需要某种类型的数据集?
注意:一个限制是我无法访问数据集,所以我必须发送代码才能运行,并且几天内不会得到结果。这是一个非常漫长而令人沮丧的过程,但我相信有些人可以理解。
导致问题的代码是宏(在代码的开头)和最后一段使用数据集调用宏。
错误日志:
代码:
# Filename : Census2007_Hawaii_BearingCoffee_BigIsland.sas
/******************************************************************
Clearance Test Macro
input_dataset - desired dataset which variables are located
output_dataset - an output table with test results
variable_to_consider - list of variables to compute test on
*******************************************************************/
%macro clearance_test(input_dataset= ,output_dataset=, variable_to_consider=);
%let variable_to_consider=%cmpres(&variable_to_consider);
proc sql noprint;
select count(*) into : obs_count from &input_dataset;
quit;
%let obs_count=&obs_count;
proc transpose data=&input_dataset out=&output_dataset prefix=top_;
var &variable_to_consider;
run;
data &output_dataset;
set &output_dataset end=eof;
array top(*) top_&obs_count.-top_1;
x=dim(top);
call sortn(of top[*]);
total=sum(of top[*]);
top_2_total=sum(top_1, top_2);
if sum(top_1,top_2) > 0.9 * total then Flag90=1; else Flag90=0;
if top_1 > total * 0.6 then Flag60=1; else Flag60=0;
keep total top_1 top_2 _name_ top_2_total total Flag60 Flag90;
run;
%mend mymacro;
/***********************************************************************/
*Define file path statics;
Libname def 'P:\Hawaii_Arita\John_Hawaii_Coffee\Datasets';
Libname abc "P:\Hawaii_Arita\John_Hawaii_Coffee\Datasets";
option obs=max;
/* Initialize database */
DATA def.Census2007_Hawaii_Coffee;
SET abc.census2007_hawaii_SubSet_Coffee;
**<create the variables used in the macro> **;
RUN;
/* Clearance Test Results */
%clearance_test(input_dataset=def.census2007_hawaii_SubSet_Coffee, output_dataset=test_data ,variable_to_consider= OIR OIRO ROA ROAO SProfit
LProfit SProfitAcre LProfitAcre Profitable MachineandRent UtilityandFuel LaborH LaborO FertilizerandChem MaintandCustom
Interest Tax Dep Others TFPE_cal operators workers operatorsandworkers)
一个完整/可验证的例子:
这已经在远程机器上进行了测试并且可以完美运行。
/* Create test data set*/
data business_data;
do firm = 1 to 3;
revenue = rand("uniform");
costs = rand("uniform");
profits = rand("uniform");
vcost = rand("uniform");
output;
end;
run;
/******************************************************************
Clearance Test Macro
input_dataset - desired dataset which variables are located
output_dataset - an output table with test results
variable_to_consider - list of variables to compute test on
*******************************************************************/
%macro clearance_test(input_dataset= ,output_dataset=, variable_to_consider=);
%let variable_to_consider=%cmpres(&variable_to_consider);
proc sql noprint;
select count(*) into : obs_count from &input_dataset;
quit;
%let obs_count=&obs_count;
proc transpose data=&input_dataset out=&output_dataset prefix=top_;
var &variable_to_consider;
run;
data &output_dataset;
set &output_dataset end=eof;
array top(*) top_&obs_count.-top_1;
x=dim(top);
call sortn(of top[*]);
total=sum(of top[*]);
top_2_total=sum(top_1, top_2);
if sum(top_1,top_2) > 0.9 * total then Flag90=1; else Flag90=0;
if top_1 > total * 0.6 then Flag60=1; else Flag60=0;
keep total top_1 top_2 _name_ top_2_total total Flag60 Flag90;
run;
%mend mymacro;
/* Print summary table, run macro, and print clearance test table */
PROC MEANS data = business_data n sum mean median std;
VAR revenue costs profits vcost;
RUN;
%clearance_test(input_dataset=business_data, output_dataset=test_data ,
variable_to_consider=revenue costs profits vcost)
proc print data = test_data; run;
【问题讨论】:
-
我删除了大部分代码,因为它与问题没有任何关系。
-
@Joe 谢谢!我只是想我应该删除子设置部分,但你删除了我认为相关的文件路径。
-
文件路径几乎不相关:毕竟它们只在你的机器上有用,而且它们与错误无关[除非你使用了错误的路径,但我们怎么会知道这一点或能够提供帮助吗?] 并且数据步骤和后续 proc 方法是无关紧要的,因为它们不向宏提供任何输入。
-
等等,也许数据步骤是相关的。您是否打算将数据步骤的结果作为宏的输入?因为目前不是,所以当前宏采用
set数据集(初始输入)。 -
@Joe 是的,我希望输入是作为子集的数据集。
标签: sas