SAS中是否可以使用proc sql在标签中打印变量的值?

时间:2018-10-11 19:40:20

标签: sas label proc

我遇到一种情况,我想将变量的值放在SAS的标签中。 示例:Total_Days的中位数为2。我想将此值放在Days_Median_Split标签中。中位数会随着数据的变化而不断变化,所以我想使其自动化。

  • Phy_Activity总天数“ Days_Median_Split:中位数为2的天数”
  • 否0 0
  • 否0 0
  • 是2 1
  • 是3 1
  • 是5 1

Sample Dataset

非常感谢!

1 个答案:

答案 0 :(得分:1)

* step 1 create data;
data have;
input Phy_Activity $ Total_Days Days_Median_Split;
datalines;
No 0 0
No 0 0
Yes 2 1
Yes 3 1 
Yes 5 1
run;

*step 2 sort data on Total_days;
proc sort data = have;
by Total_days;
run;

*step 3 get count of obs;
proc sql noprint;
select count(*) into: cnt
from have;quit;

* step 4 calulate median;
%let median = %sysevalf(&cnt/2 + .5);


*step 5 get median obsevation;
proc sql noprint;
select Total_days into: medianValue
from have
where monotonic()=&median;quit;

*step 6 create label;
data have;
set have;
label Days_Median_split = 'Days_Median_split: Number of Days with Median '  
%trim(&medianValue);
run;