簡體   English   中英

SAS:PROC FREQ自動組合?

[英]SAS: PROC FREQ combinations automatically?

我有一個看起來像下表的患者數據集,我想看看哪些疾病一起運行並最終制作熱圖 我使用PROC FREQ來制作這個列表,但是這樣做太費力了,因為它給了我每一個組合(數千)。

Moya    Hypothyroid Hyperthyroid    Celiac
   1       1           0             0
   1       1           0             0       
   0       0           1             1
   0       0           0             0
   1       1           0             0
   1       0           1             0
   1       1           0             0
   1       1           0             0
   0       0           1             1
   0       0           1             1


proc freq data=new;
tables HOHT*HOGD*CroD*Psor*Viti*CelD*UlcC*AddD*SluE*Rhea*PerA/list;
run;

我最終會喜歡下面顯示的一組交叉標簽,所以我可以看到每個組合有多少患者。 顯然,可以手動復制粘貼每個變量,但有沒有辦法快速查看或自動執行此操作?

proc freq data=new;
tables HOHT*HOGD/list;
run;

proc freq data=new;
tables HOHT*CroD/list;
run;


proc freq data=new;
tables HOHT*Psor/list;
run;

謝謝!

可以使用TABLES語句控制PROC FREQ生成的TABLES 要生成作為數據集中所有列對的雙向列聯表的表,可以編寫循環通過變量列表的SAS宏,並生成TABLES語句以創建所有正確的列聯表。

例如,使用原始帖子中的數據:

data xtabs;
input Moya    Hypothyroid Hyperthyroid    Celiac;
datalines;
   1       1           0             0
   1       1           0             0       
   0       0           1             1
   0       0           0             0
   1       1           0             0
   1       0           1             0
   1       1           0             0
   1       1           0             0
   0       0           1             1
   0       0           1             1
;
run;
%macro gentabs(varlist=);
   %let word_count = %sysfunc(countw(&varlist));
   %do i = 1 %to (&word_count - 1);
      tables %scan(&varlist,&i,%str( )) * (
      %do j = %eval(&i + 1) %to &word_count;
        %scan(&varlist,&j,%str( ))
      %end; )
      ; /* end tables statement */
   %end;
%mend;
options mprint;
proc freq data = xtabs;
  %gentabs(varlist=Moya Hypothyroid Hyperthyroid Celiac)
  run;

SAS宏生成的代碼是:

 73         proc freq data = xtabs;
 74           %gentabs(varlist=Moya Hypothyroid Hyperthyroid Celiac)
 MPRINT(GENTABS):   tables Moya * ( Hypothyroid Hyperthyroid Celiac ) ;
 MPRINT(GENTABS):   tables Hypothyroid * ( Hyperthyroid Celiac ) ;
 MPRINT(GENTABS):   tables Hyperthyroid * ( Celiac ) ;
 75         run;

...並且結果輸出中的前幾個表看起來像:

在此輸入圖像描述

要向TABLES語句添加選項,可以在行上的分號之前添加代碼,注釋為/* end tables statement */

Proc MEANS是一種用於獲取數據中組合組的各種統計數據的常用工具。 在您的情況下,您只需要每個組合的計數。

假設您有10,000名患者,其中包含10個二元因子

data patient_factors;
  do patient_id = 1 to 10000;
    array factor(10);
    do _n_ = 1 to dim(factor);
      factor(_n_) = ranuni(123) < _n_/(dim(factor)+3);
    end;
    output;
  end;
  format factor: 4.;
run;

正如您所提到的, Proc FREQ可以計算每個10級組合的計數。

proc freq noprint data=patient_factors;
  table 
    factor1
    * factor2 
      * factor3
        * factor4
          * factor5
            * factor6
              * factor7
                * factor8
                  * factor9
                    * factor10
  / out = pf_10deep
  ;
run;

FREQ沒有語法來支持創建包含涉及factor1每個成對組合的輸出數據。

Proc MEANS 確實具有此類輸出的語法。

proc means noprint data=patient_factors;
  class factor1-factor10;
  output out=counts_paired_with_factor1 n=n;
  types factor1 * ( factor2 - factor10 );
run;

暫無
暫無

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

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