簡體   English   中英

SAS將可變格式放在標題中

[英]SAS put variable format in title

我有一個名為agegroup的變量,它具有許多類別,例如:1 =“ 0-5” 2 =“ 6-10”等。

如果我創建一個宏打印數據agegroup ,並希望在標題中年齡組的格式,我該怎么辦呢?

%macro ageprint(agegrp=1);
 proc print data=age;
 title "Age group &agegrp";
 run;
%mend;

如果我運行此宏,則希望標題顯示為“ 0-5歲年齡組”,而不是“ 1歲年齡組”。

有人提示嗎?

謝謝!

您也可以使用#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;

像這樣嗎

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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM