测试 SAS 宏中的空参数 [英] Testing for an empty parameter in a SAS Macro

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

问题描述

例如,我有一个宏程序

%macro test(parameter1= , parameter2=, parameter3=);
  DATA data_gender;
  SET data_input(WHERE=(gender=parameter3));
  RUN;
  .....
%mend;

基本上,我使用参数 3(男性或女性)选择了观察结果.现在我想创建第三个选项:当参数 3 为空时(不声明此参数的值),将两个观察值都保留在男性和女性中.

Basically, i made a selection of observations using the parameter3 (Male or Female). Now i want to create a third option: to keep both observations in Male and Female when the parameter3 is empty (without declaring the value of this parameter).

%test(parameter1=xxx , parameter2=yyy, parameter3=);

你能告诉我我该怎么做吗?

Can you tell me how can i do that please?

推荐答案

同意 Joe 的回答.他们在论文中提出的一个好处是他们正在测试空白,无论参数为 null 还是其中有空白,他们的测试都将返回 true.有时进行区分空参数和空白参数的测试很有用.该论文提到 %length(%superq( )) 作为 null 的可能测试.例如,这允许您为性别指定一个空白值,并获得与当性别为空时不同的结果.

Agree with Joe's answer. One good point they make in the paper is they are testing for blank, and their test will return true whether a parameter is null or has blanks in it. Sometimes it is useful have a test that differentiates between a parameter that is null and one that has blanks. The paper mentions %length(%superq( )) as a possible test for null. For example below, this allows you to specify a blank value for sex, and get a different result than you do when sex is null.

data class;
  set sashelp.class;
  if _n_=1 then sex='';
run;

%macro test2(parameter1= , parameter2=, sex=);
  DATA data_gender;
  SET class(
            %if %length(%superq(sex)) %then %do;
              where=(sex="&sex.")
            %end;
           );
  RUN;
%mend;

%test2(sex=)
%test2(sex=%str( ))

这篇关于测试 SAS 宏中的空参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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