我有一个用宏代码创建的表。使用此表我需要创建一个提示。为了创建提示,我在第二部分有另一个宏。我该如何组合这两个代码。它给出了错误。说数据不存在:
%macro bygroup(y);
data recommendations_macro;
set recommendations (where=(maingroup=&y));
run;
data issues_macro;
set issues (where=(maingroup=&y));
run;
proc sort data=recommendations_macro (drop=issue);
by SFVFDBK_STUDENT_PIDM count;
run;
proc sort data=issues_macro (drop=Recommendation );
by SFVFDBK_STUDENT_PIDM count;
run;
data rec_and_issues ;
merge recommendations_macro (in=a)
issues_macro (in=b);
by SFVFDBK_STUDENT_PIDM count;
if a or b;
run;
%mend;
在这里创建了表格,我需要添加它:
%macro missing_or_nonmissing(sel=);
%let not = %sysfunc(ifc(&sel=NonMissing,not,));
SVFDBK_FEEDBACK_COMMENTS is ¬. null
%mend missing_or_nonmissing;
DATA rec_and_issues;
set rec_and_issues;
where %missing_or_nonmissing(sel=&sel_issue) ;
run;
proc sort data=rec_and_issues (where=(%missing_or_nonmissing(sel=&sel_issue.)));
by SFVFDBK_STUDENT_PIDM;
run;
答案 0 :(得分:1)
%macro bygroup(y); proc sort data=recommendations (where=(maingroup=&y) drop=issue) out=recommendations_macro; by SFVFDBK_STUDENT_PIDM count; run; proc sort data=issues (where=(maingroup=&y) drop=recommendation) out=issues_macro; by SFVFDBK_STUDENT_PIDM count; run; data rec_and_issues ; merge recommendations_macro (in=a) issues_macro (in=b); by SFVFDBK_STUDENT_PIDM count; if a or b; run; %mend; %bygroup('hello')
我还会更改where=
数据集选项以匹配maingroup的列类型。 e.g。
如果是字符:
where maingroup="&y"
如果是数字:
where maingroup=&y
这样可以将宏调用简化为:
%bygroup(test)
或
%bygroup(3)