我想将在 IML 中计算的值用于 SAS 的打印功能 %PRNTINIT。此功能用于从可以更新的数据库中提供每周报告。
我有一些遗留代码用于proc sql
声明稍后调用的宏类型值,例如:
声明变量:tot1-tot4
*Get total number of subjects in each group in macro variable;
proc sort data = avg3; by description; run;
proc sql noprint;
select _freq_
into: tot1-:tot4
from avg3;
quit;
调用变量 tot1-tot4 进行打印
%print(column = 1, style = bold, just = center, lines = bottom:none);
%print("(N= &tot1)", column = 2, just = center, lines = bottom:none);
%print("(N= &tot2)", column = 3, just = center, lines = bottom:none);
%print("(N= &tot3)", column = 4, just = center, lines = bottom:none);
%print("(N= &tot4 )", column = 5, just = center, lines = bottom:none);
%print(column = 6, just = center, lines = bottom:none);
如果可能的话,我希望能够类似地从 IML 调用值。
示例数据:
data test ;
input age type gender $;
cards;
1 1 m
1 1 m
1 1 m
1 1 f
1 1 f
1 2 f
2 1 m
2 1 f
2 2 m
2 2 m
2 2 m
2 2 m
2 2 m
2 2 f
2 2 f
2 2 f
;
proc freq data = test;
tables type*age / chisq norow nocol nopercent outexpect out=out1 ;
tables type*gender / chisq norow nocol nopercent outexpect out=out2 ;
run;
options missing=" ";
proc iml;
reset print;
use out2;
read all var {count} into count;
type1 = count[1:2] ;
type2 = count[3:4] ;
tab = type1 || type2 ;
cols = tab[+,] ;
rows = tab[,+] ;
tot = sum(tab) ;
perc = round(cols / tot, .01) ;
cell_perc = round(tab / (cols//cols) , .01) ;
expect = (rows * cols) / tot ;
chi_1 = sum((tab - expect)##2/expect) ;
p_chi_1 = 1-CDF('CHISQUARE',chi_1, ((ncol(tab)-1)*(nrow(tab)-1)));
print tab p_chi_1 perc cell_perc;
out_sex = tab || (. // p_chi_1);
print out_sex;
print out_sex[colname={"1","2"}
rowname={"f" "m" "p-value"}
label="Table of Type by Gender"];
call symput(t1_sum, cols[1,1]) ;
%let t2_sum = put(cols[1,2]) ;
%let t1_per = perc[1,1] ;
%let t2_per = perc[1,2] ;
%let t1_f = tab[1,1] ;
%let t1_m = tab[2,1] ;
%let t2_f = tab[1,2] ;
%let t2_m = tab[2,2] ;
%let t1_f_p = cell_perc[1,1] ;
%let t1_m_p = cell_perc[2,1] ;
%let t2_f_p = cell_perc[1,2] ;
%let t2_m_p = cell_perc[2,2] ;
%let p_val = p_chi_1 ;
***** is it possible to list output values here for use in table building ??? ;
* like: %let t1_f = tab[1,1]
%let t2_f = tab[2,1] etc... ;
quit;
所以我想声明一个打印语句,如下所示:
%print( "(N=&tab[1,1], column = 1, just=center, lines = bottom:none);
%print( "(N=&tab[1,2], column = 2, just=center, lines = bottom:none);
etc...
非常感谢您对此的任何帮助...
更新:无法从 IML 中提取声明的宏值
我已经能够计算出正确的值并成功格式化表格。
但是,我无法提取用于打印宏的值。
我在 IML 中创建了一些矩阵和计算值,但是当我尝试声明宏变量以供以后使用时,唯一返回的是我将变量声明为的文字值......例如:
和
您可以在表格中看到我想要的数字,但到目前为止还没有成功。我尝试使用%let
, put
, symput
, 并symputx
没有成功。
call symput(t1_sum, cols[1,1]) ;
%let t2_sum = put(cols[1,2]) ;
%let t1_per = perc[1,1] ;
%let t2_per = perc[1,2] ;
%let t1_f = tab[1,1] ;
%let t1_m = tab[2,1] ;
%let t2_f = tab[1,2] ;
%let t2_m = tab[2,2] ;
%let t1_f_p = cell_perc[1,1] ;
%let t1_m_p = cell_perc[2,1] ;
%let t2_f_p = cell_perc[1,2] ;
%let t2_m_p = cell_perc[2,2] ;
布雷格...