【问题标题】:Diabetes: Prediction using discrimination on PCA糖尿病:使用对 PCA 的歧视进行预测
【发布时间】:2015-07-26 15:56:08
【问题描述】:

我有一张桌子:

col1    col2 
2        20
2.5      25 
2.67     30 
2.99     40

我正在寻找

varone = 2 x col2, vartwo= 2.5 x col2, varthree= 2.67 x col3, varfour=2.99 x col2

即从表中提取特定值
然后将整列乘以该值 (scalar x vector)。

我尝试转置col1

col1a  col1b  col1c col1d      col2
2       2.5   2.67   2.99      20
                               25 
                               30 
                               40

然后尝试将col1a x col2 相乘,但似乎没有用。

【问题讨论】:

  • 由于您已经使用 SQL 标记了它,因此提供更多详细信息可能会很有用:您可能已经尝试过哪些查询,以及您正在使用哪种 SQL。

标签: sql statistics sas


【解决方案1】:

你可以利用数组来实现。

以下程序是动态的。它适用于任意数量的观察。

****data we have****;
data have;
input col1 col2;
datalines;
2        20
2.5      25
2.67     30
2.99     40
;
run;

****Taking Count****;
****Creating macro "value" to store col1 data****;
proc sql ;
    select count(*) into :cnt_rec from have;
    select col1 into :value1 - :value&SysMaxLong from have;
quit;


data want(drop=i);
    set have;

    array NewColumn(&cnt_rec);

    ****processing the array and multiplying col2 data****;

    do i = 1 to &cnt_rec;
        NewColumn[i] = symget('value'||left(i)) * col2;
    end;
run;

【讨论】:

    【解决方案2】:

    假设您使用的是 SAS 和 PROC FACTORPROC PRINCOMP,那么您可以使用 PROC SCORE

    直接来自文档的示例:

    http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_score_sect017.htm

     /* This data set contains only the first 12 observations   */
       /* from the full data set used in the chapter on PROC REG. */
     data Fitness;
       input Age Weight Oxygen RunTime RestPulse RunPulse @@;
       datalines;
    44 89.47  44.609 11.37 62 178     40 75.07  45.313 10.07 62 185
    44 85.84  54.297  8.65 45 156     42 68.15  59.571  8.17 40 166
    38 89.02  49.874  9.22 55 178     47 77.45  44.811 11.63 58 176
    40 75.98  45.681 11.95 70 176     43 81.19  49.091 10.85 64 162
    44 81.42  39.442 13.08 63 174     38 81.87  60.055  8.63 48 170
    44 73.03  50.541 10.13 45 168     45 87.66  37.388 14.03 56 186
    ;
    proc factor data=Fitness outstat=FactOut
                method=prin rotate=varimax score;
       var Age Weight RunTime RunPulse RestPulse;
       title 'Factor Scoring Example';
    run;
    proc print data=FactOut;
       title2 'Data Set from PROC FACTOR';
    run;
    proc score data=Fitness score=FactOut out=FScore;
       var Age Weight RunTime RunPulse RestPulse;
    run;
    proc print data=FScore;
       title2 'Data Set from PROC SCORE';
    run;
    

    【讨论】:

      【解决方案3】:

      在 SAS 中,您可以只使用 proc sql:

      proc sql;
          select 2*col2 as varone, 2.5*col2 as vartwo, 2.67*col3 as varthree, 2.99*col2 as varfour
          from atable;
      

      【讨论】:

        猜你喜欢
        • 2017-06-14
        • 2019-11-11
        • 1970-01-01
        • 2013-11-03
        • 2019-02-15
        • 2011-09-14
        • 2020-12-06
        • 2019-01-27
        • 2018-12-20
        相关资源
        最近更新 更多