首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SAS在标题中放入变量格式

SAS在标题中放入变量格式
EN

Stack Overflow用户
提问于 2014-10-18 05:21:12
回答 2查看 1.2K关注 0票数 1

我有一个名为agegroup的变量,它有许多类别,例如: 1="0-5“2="6-10”等。

如果我创建了一个通过agegroup打印数据的宏,并且想要在标题中使用年龄组格式,我该怎么做?

代码语言:javascript
运行
复制
%macro ageprint(agegrp=1);
 proc print data=age;
 title "Age group &agegrp";
 run;
%mend;

如果我运行这个宏,我希望标题打印为"Age group 0-5“而不是"age group 1”。

有谁有提示吗?

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2014-10-18 08:37:45

您也可以使用#byval(age)选项,它采用标题中的格式值:

代码语言:javascript
运行
复制
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;

如果需要宏来控制输出的位置,您仍然可以使用相同的方法,例如:

代码语言:javascript
运行
复制
%macro ageprint(agegrp=1);
 proc print data=age;
 by agegrp;
 title "Age group #byval(agegrp)";
 run;
 %mend;
票数 3
EN

Stack Overflow用户

发布于 2014-10-18 06:20:03

像这样的东西?

代码语言:javascript
运行
复制
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);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26433608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档