我有一个名为agegroup
的变量,它有许多类别,例如: 1="0-5“2="6-10”等。
如果我创建了一个通过agegroup
打印数据的宏,并且想要在标题中使用年龄组格式,我该怎么做?
%macro ageprint(agegrp=1);
proc print data=age;
title "Age group &agegrp";
run;
%mend;
如果我运行这个宏,我希望标题打印为"Age group 0-5“而不是"age group 1”。
有谁有提示吗?
谢谢!
发布于 2014-10-18 08:37:45
您也可以使用#byval(age)选项,它采用标题中的格式值:
proc format ;
value grpformat
0 - 12 = '0 - 12'
12 - 14 = '12 - 14'
other = 'other'
;
run;
proc sort data=sashelp.class out=class; by age; run;
proc print data=class;
by age;
format age grpformat.;
title "Age Group #byval(age)";
run;
如果需要宏来控制输出的位置,您仍然可以使用相同的方法,例如:
%macro ageprint(agegrp=1);
proc print data=age;
by agegrp;
title "Age group #byval(agegrp)";
run;
%mend;
发布于 2014-10-18 06:20:03
像这样的东西?
proc format ;
value grpformat
0 - 5 = '0 - 5'
6 - 10 = '6 - 10'
other = 'other'
;
run;
%macro ageprint(agegrp);
proc print data=age;
where agegrp=&agegrp;
title "Age group %sysfunc(putn(&agegrp, grpformat.))";
run;
%mend;
%ageprint(agegrp=2);
%ageprint(agegrp=8);
https://stackoverflow.com/questions/26433608
复制相似问题