宏未加载数据集 [英] Macro not loading data set

查看:28
本文介绍了宏未加载数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

变量检查和汇总输出

输出带有SAS测试结果表的宏表

从之前的帖子中,我认为我能够运行宏并产生所需的结果.但是,在最终收到输出不起作用的报告后,我真的很困惑为什么我会收到缺少变量的错误.看起来好像在子设置后没有加载数据集.我能够处理基本的汇总统计表,但是当我加载宏时,输出不起作用.

From the previous posts, I thought I was able to run the macro and produce the desired results. However, after finally getting a report back that the output is not working I'm really confused as to why I'm getting the error that there were missing variables. It appears as if the data set is not being loaded after sub-setting. I'm able to process basic summary statistic tables, but when I load the macro the output is not working.

为什么数据集没有加载?宏是否需要某种类型的数据集?

Why is the data set not loading? Does a macro require a certain type of data set?

注意:一个限制是我无权访问数据集,所以我必须发送代码才能运行并且几天内不会得到结果.这是一个非常漫长且令人沮丧的过程,但我相信有些人可以理解.

Note : A limitation is that I do not have access to the data set, so I must send code to be run and won't get results for a few days. It's a very long and frustrating process, but I'm sure some can relate.

导致问题的代码是宏(在代码的开头)和使用数据集调用宏的最后一部分.

The code that is causing problems is the macro (in beginning of code) and the very last section which calls the macro with the data set.

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

完整/可验证的示例:

这已经在远程机器上测试过并且运行良好.

A Complete/Verifiable Example :

This has been tested on the remote machine and works perfectly.

/* 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;

推荐答案

这是一个最小的、完整的可验证示例 (MCVE) 有助于测试您的问题是代码问题还是数据问题的地方.

This is where a minimal, complete verifiable example (MCVE) would be helpful for testing whether your problem is a problem with the code, or the data.

>

这是上面的代码,但有一个 SASHELP 数据集(这些是 SAS 内置的,所以每个人都有).

Here's the code above, but with a SASHELP dataset (those are built-in to SAS so everyone has them).

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

那是确切的宏,只是使用不同的输入数据集.它在我的机器上正常工作(标志变量没有意义,因为数据不适合它们,但代码有效).

That's the exact macro, just using a different input dataset. It works correctly on my machine (the flag variables are meaningless since the data isn't right for them, but the code works).

在你同事的机器上运行同样的程序,如果它运行了,那么你就知道数据有问题(即,数据集没有你认为的变量).如果它没有运行,那么你有其他一些问题(也许是提交方式的问题,也许你最终得到了虚假字符或其他东西).

Run the same on your colleague's machine, and if it runs, then you know the data is the problem (ie, the dataset doesn't have the variables you think it does). If it doesn't run, then you have some other problem (perhaps an issue with how it's being submitted, maybe you end up with spurious characters or something).

这篇关于宏未加载数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆