TRANSPOSEプロシジャ


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。


<データの転置>
/*テストデータ*/
proc format ;
  value f_sex 1 = "男"
              2 = "女";
  value noyes 0 = "NO"
              1 = "YES";
run;
 
data test;
  length sex 8. drug $10 smoke 8.;
  do i = 1 to 112 ; drug = "medicine" ; sex = 1 ; smoke = 0 ; output; end;
  do i = 1 to 137 ; drug = "medicine" ; sex = 1 ; smoke = 1 ; output; end;
  do i = 1 to  83 ; drug = "medicine" ; sex = 2 ; smoke = 0 ; output; end;
  do i = 1 to 141 ; drug = "medicine" ; sex = 2 ; smoke = 1 ; output; end;
  do i = 1 to  90 ; drug = "plasebo"  ; sex = 1 ; smoke = 0 ; output; end;
  do i = 1 to  75 ; drug = "plasebo"  ; sex = 1 ; smoke = 1 ; output; end;
  do i = 1 to  86 ; drug = "plasebo"  ; sex = 2 ; smoke = 0 ; output; end;
  do i = 1 to  64 ; drug = "plasebo"  ; sex = 2 ; smoke = 1 ; output; end;
run;

<薬剤別、性別と喫煙者の有無のクロス集計>

proc freq data = test ;
  tables drug * sex * smoke / out = test1(drop = PERCENT); 
  format sex f_sex. smoke noyes.;
run;

<薬剤を横に転置・・・転置した変数名の接頭語を指定>

proc sort data = test1 out = s_test1 ;
  by sex smoke;
run;
 
proc transpose data = s_test1 out = tran1 prefix=var_;
  var count ;
  by sex smoke;
run;

<薬剤を横に転置・・・IDを指定>

proc transpose data = s_test1 out = tran2 ;
  var count ;
  by sex smoke;
  id drug ;
run;

<喫煙者の有無を横に転置>

proc sort data = test1 out = s_test1 ;
  by sex drug ;
run; 
 
proc transpose data = s_test1 out = tran3 ;
  var count ;
  by sex drug ;
  id smoke ;
run;

<formatを別変数に持つテストデータ>

 
data test2 ;
  set test1 ;
  format smoke 8. ;
  length  s_lab $8 ; 
  s_lab=put(smoke,noyes.);
run;
 
proc sort data = test2 out = s_test2 ;
  by sex drug ;
run;

<IDLABELの指定例>

proc transpose data = s_test2 out = tran4 ;
  var count ;
  by sex drug ;
  id smoke ;
  idlabel s_lab ;
run;



ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。