1

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でいくつかの行列と計算値を作成しましたが、後で使用するためにマクロ変数を宣言しようとすると、返されるのは、変数を宣言したリテラル値だけです...例:

IML値が欠落しているテーブル

IML値が欠落している別のテーブル

表で私が数字をどのようにしたいかを見ることができますが、これまでのところ成功していません。、、、を使用してみましたが%let、成功しませんでした。putsymputsymputx

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

Blerg..。

4

2 に答える 2

0

SAS/IML マトリックスは、すべて数値またはすべて文字でなければなりません。これが、試みがうまくいかなかった理由です。ただし、SAS/IML PRINT ステートメントには、列や行にラベルを付けたり、フォーマットを適用したりできるいくつかのオプションがあります。http://blogs.sas.com/content/iml/2011/08/01/options-for-printing-a-matrix/を参照してください 。 グローバル SAS OPTIONS ステートメントと合わせて、必要な出力を取得できると思います。

1) グローバル ステートメントを使用する

options missing=" ";

欠損値を空白として出力するように SAS に指示します。

2) あなたの目標は、2x2 TAB マトリックスに列を追加することです。データのない行に (数値の) 欠損値を使用できます。

   out_age = tab || (. // p_chi_1);

3) この 2x3 テーブルを印刷し、COLNAME= および ROWNAME= オプションを使用して行見出しを表示できます。

print out_age[rowname={"1","2"} 
              colname={"f" "m" "p-value"}
              label="Table of Type by Gender"];

古いスタイルのマクロを本当に使用したい場合は、次の記事に示すように、SYMPUTX ステートメントを使用して SAS/IML からマクロ変数に値をコピーできます: http://blogs.sas.com/content/iml/2011 /10/17/does-symput-work-in-iml/

于 2012-12-29T19:07:30.573 に答える
0

SOで多くの検索を行い、いくつかのヘルプを見つけた後、答えをつなぎ合わせることができました。

  1. 出力値は文字列でなければなりません
  2. マクロ変数の名前は引用符で囲む必要があります
  3. symputx余分な空白を削除するには、呼び出しを to にする必要があります ( と比較した場合symput)

IML 値をマクロ変数に抽出するコード

call symputx('t1_sum', char(cols[1,1])) ;
call symputx('t2_sum', char(cols[1,2])) ;

call symputx('t1_per', char(perc[1,1])) ;
call symputx('t2_per', char(perc[1,2])) ;

call symputx('t1_f' , char(tab[1,1])) ;
call symputx('t1_m' , char(tab[2,1])) ;
call symputx('t2_f' , char(tab[1,2])) ;
call symputx('t2_m' , char(tab[2,2])) ;

call symputx('t1_f_p' , char(cell_perc[1,1])) ;
call symputx('t1_m_p' , char(cell_perc[2,1])) ;
call symputx('t2_f_p' , char(cell_perc[1,2])) ;
call symputx('t2_m_p' , char(cell_perc[2,2])) ;

call symputx('p_val' , char(round(p_chi_1, .001))) ;

古い SAS %PRNTINIT マクロを使用してテーブルを構築するために使用される部分的なコード

...
%print("Female",            column = 1,  just = center  );
%print("&t1_f (&t1_f_p)",   column = 2,  just = center  );
%print("&t2_f (&t2_f_p)",   column = 3,  just = center  );
%print(,                    column = 4,  just = center  );
%print(proc = newrow);

%print("Male",              column = 1,  just = center  );
%print("&t1_m (&t1_m_p)",   column = 2,  just = center  );
%print("&t2_m (&t2_m_p)",   column = 3,  just = center  );
%print("&p_val",            column = 4,  just = center  );
...

望ましい結果:

正しい数字を含む表の詳細

正しい数字を含む追加のテーブルの詳細

于 2013-01-02T19:55:38.000 に答える