Macro not loading data set

2019-09-28 03:35发布

曾任:

可变检查和总结出

宏与SAS表中的测试结果输出表

问题/问题

从以前的帖子,我想我是能够运行宏,并产生预期的效果。 然而,在最后得到一个回来报告,输出不工作我,为什么我得到的错误,有遗漏变量真的很困惑。 它看起来好像数据集没有被后分装的设置。 我能处理基本概要统计数据表,但是当我加载宏输出不工作。

为什么是数据集不加载? 请问宏需要某种类型的数据集?

注意:一个限制是,我没有访问到数据集,所以我必须向运行的代码,并不会得到几天的结果。 这是一个非常漫长而令人沮丧的过程,但我敢肯定,一些可以涉及。

这是导致问题的代码是宏(在代码开头)和最后一节,其要求与数据集的宏。

错误日志:

代码:

# 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;

Answer 1:

这是一个最小的,完整的可核查的例子(MCVE)将是测试你的问题是否与代码或数据的问题很有帮助。

下面是上面的代码,但有SASHELP数据集(这些都是内置在SAS所以每个人都有他们)。

%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 clearance_test;


%clearance_test(input_dataset=sashelp.cars, output_dataset=work.test, variable_to_consider=mpg_city mpg_highway);

这是确切的宏,只是用不同的输入数据集。 它工作正常在我的机器上(旗变量是没有意义的,因为数据是不正确的,但是,如果代码工作)。

运行你的同事的机器上是相同的,如果它运行,那么你知道的数据是问题(即数据集没有,你认为它的变量)。 如果它不运行,那么你有其他问题(也许它如何被提交的问题,也许你最终虚假字符或东西)。



文章来源: Macro not loading data set
标签: sas