Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用转置的SAS多标志_Sas - Fatal编程技术网

使用转置的SAS多标志

使用转置的SAS多标志,sas,Sas,我寻求您的帮助,在SAS中创建下表 我有这张桌子: Policy no Policy type ID_Payor1 ID_Payor2 ID_Insured1 ID_Insured2 ID_Owner1 ID_Owner2 123 P1 A - B - A - 124 P2 B - - - - - 124 P1 A - C - C - 我希望创建的是这样的东西,它将整合每个ID具有的保单类型的数量: ID Co

我寻求您的帮助,在SAS中创建下表

我有这张桌子:

Policy no   Policy type ID_Payor1   ID_Payor2   ID_Insured1 ID_Insured2 ID_Owner1   ID_Owner2
123 P1  A   -   B   -   A   -
124 P2  B   -   -   -   -   -
124 P1  A   -   C   -   C   -
我希望创建的是这样的东西,它将整合每个ID具有的保单类型的数量:

ID  Countflag_P1_Payor  Countflag_P1_Owner  Countflag_P1_Insured    Countflag_P2_Payor  Countflag_P2_Owner  Countflag_P2_Insured    
A   2   1   0   0   0   0   
B   0   0   1   1   0   0   
C   0   1   1   0   0   0   
我非常感谢你的帮助


谢谢,

我想您需要一个proc freq或summary来开始累积计数。为abc创建一种格式,并在proc summary中使用preload-fmt选项似乎是一种可行的方法

您希望以这种方式创建格式并执行过程摘要的原因是,您需要生成一个数据集,该数据集对每种策略类型都有a、B和C计数,即使这些组合不存在。就像在示例数据中没有任何C for ID_payr1一样,但您仍然希望生成在该列中显示C计数为0的行

    data table1;
 input Policy_no  
       Policy_type $ ID_Payor1 $ ID_Payor2 $ 
       ID_Insured1  $ ID_Insured2 $  ID_Owner1 $  ID_Owner2  $;
 datalines;
123 P1 A . B . A .
124 P2 B . . . . .
124 P1 A . C . C .
;


proc format;
   value $abc
            'A'='A'
            'B'='B'
            'C'='C'
            '.'='-'
    ;
run;

proc summary data=table1 completetypes nway;
   class  ID_Payor1 ID_Payor2 
          ID_Insured1 ID_Insured2 ID_Owner1 
          ID_Owner2 /preloadfmt missing;
   class policy_type;
   types policy_type * (ID_Payor1 ID_Payor2 ID_Insured1
                        ID_Insured2 ID_Owner1 ID_Owner2);
   output out=sumt1;
   format ID_Payor1 ID_Payor2 ID_Insured1 ID_Insured2 ID_Owner1 ID_Owner2 $abc.;
run;


proc print data=sumt1;
此时,sumt1数据集的每一列都有一个B和C的频率计数,每个变量以及P1和P2都缺少as-by。这还不是你想要的,但现在已经准备好了。此数据集太大,无法在此处打印-它很长而不是很宽,并且在列中有许多缺少的值。但是,在这一点上检查过程打印的结果,看看你得到了什么

对于转置多个列,我们需要在每个列上运行一次proc transpose,然后合并结果。宏似乎是一种方法

在转置之前,我还将对大型数据集进行子集设置,以便我们只拥有包含转置列数据的行

%global freqtables;

%MACRO transall(mCol);

   data tmp_col;   
    set sumt1; 
     if &mCol. in ('A','B','C');

   proc transpose data=tmp_col 
                  out=outTrans_&mCol.(rename= &mCol.=IDabc) prefix=&mCol._;
      by &mCol.;
      id policy_type;
      var _FREQ_;
   run;

   %let freqtables = &freqtables outTrans_&mCol.(drop= _NAME_); 
     %* using freqtables macro variable to autogenerate a list;
     %* of tables for merging later;
%MEND transall;

%transall(ID_Payor1);
     %transall(ID_Payor2);
     %transall(ID_Insured1);
     %transall(ID_Insured2);
     %transall(ID_Owner1);
     %transall(ID_Owner2);   
*创建另一个宏来循环变量的额外点数*而不是上面提到的——特别是如果你有更多的专栏

data combined_counts;
        merge &freqtables;
        by IDabc;
       run;
proc print data=combined_counts; 

此时,您应该有一张您正在寻找的桌子。

到目前为止您试过什么?也许可以先将数据集转换为每行一个ID_x,这样每行6行。