创建缺少和不丢失的提示 [英] Creating prompt for missing and nonmissing

查看:97
本文介绍了创建缺少和不丢失的提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加有关缺少或不丢失的选项的提示.此代码无法正常工作,需要修复. rec_And_issues是我在报告中创建的新表.需要选择rec_and_issues.SFVFDBK_FEEDBACK_COMMENTS是否丢失.

I am trying to add prompt for missing or nonmissing options. This code doesn't work ,need to fix that. rec_And_issues is a new table that I created in the report. Need to pick rec_and_issues.SFVFDBK_FEEDBACK_COMMENTS is missing or not.

 %macro missing_or_nonmissing;
%if "&sel_issue" eq "Missing" %then %do;
DATA rec_and_issues;
set rec_and_issues;

 rec_and_issues.SFVFDBK_FEEDBACK_COMMENTS is null;
run;
%end;

%else %if "&sel_issue" eq "NonMissing" %then %do;
DATA rec_and_issues; 
set rec_and_issues;
rec_and_issues.SFVFDBK_FEEDBACK_COMMENTS is not null;
run;  
%end;
%mend missing_or_nonmissing;

推荐答案

您不应将数据步骤放入宏中.您决定执行此操作的确切方式取决于样式-如果易于避免,我不希望在宏中不包含WHERE,因为这会使某人更容易阅读和理解您的代码-但对此的任何改动都可以.只能将部分数据步骤放入实际变化的宏中.

You shouldn't put the data step inside the macro. How exactly you decide to do this depends on style - I like to not include the WHERE in the macro if it's easily avoided, as this makes it easier for someone to read and understand your code - but any variation on this should be fine. Only put parts of the datastep in the macro that actually vary.

%macro missing_or_nonmissing(sel=);
  %let not = %sysfunc(ifc(&sel=NonMissing,not,));
  SVFDBK_FEEDBACK_COMMENTS is &not. null
%mend missing_or_nonmissing;

DATA rec_and_issues;
  set rec_and_issues;
  where %missing_or_nonmissing(sel=&sel_issue) ;
run;

没有其他理由.此外,如果您将某物用作参数,请将其用作参数.在大多数情况下,全局变量不应该在宏内部使用,在这种情况下,它显然是宏的参数,绝对不能使用全局变量.

No reason to do anything beyond that. Further, if you are using something as a parameter, use it as a parameter. Global variables shouldn't be used inside a macro in most cases, and definitely not in this case where it's clearly a parameter to the macro.

此外,您可能根本不需要这样做.如果仅过滤数据集,则几乎可以肯定,无论何时实际使用数据集(或创建数据的时间,取决于创建方式)都可以执行此操作.例如,如果下一步是PROC SORT(通常如此),则应在PROC SORT中执行此操作-该宏可以使您执行此操作. (这就是为什么我喜欢不使用WHERE的原因-因为数据集选项的语法不同).

Further, you probably don't need to do this at all. If this is solely filtering the dataset, you almost certainly can do this whenever you actually use the dataset (or when it was created, depending on how it was created). For example, if your next step is a PROC SORT, as it often is, you should just do this in the PROC SORT - and this macro lets you do that. (This is why I like to leave WHERE out of it - since where syntax differs in data set options).

proc sort data=rec_and_issues(where=(%missing_or_nonmissing(sel=&sel_issue.)));
by idvar;
run;

最后,如果您是创建提示的人,建议将基础值设置为1/0,而不是文本.这样,您不必担心大写等问题,并且可以更轻松地使用它们(因为1为"true",而0为"false").

Finally, if you're the one creating the prompt, I recommend having the underlying values be 1/0 not text. That way you don't have to worry about upcase/etc., and you can use them a bit more easily (since 1 is 'true' and 0 is 'false').

这篇关于创建缺少和不丢失的提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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