如何从“Out ='”创建SAS数据视图?选项?

时间:2018-06-13 10:55:12

标签: sas enterprise-guide

我在SAS Enterprise Guide中有一个流程流程,主要由数据视图而不是表格组成,以便在工作库中存储。

问题在于我需要从其中一个数据视图中计算百分位数(使用proc单变量)并将其连接到最终表(显示在我的流程图的屏幕截图中)。

enter image description here

有没有办法可以在单变量过程中将outfile指定为数据视图,这样程序就不会计算流程中的所有内容?当百分位数连接到决赛桌时,会再次计算流量,这样我就可以有效地将处理时间加倍。

请在下面找到单变量程序的代码

proc univariate data=WORK.QUERY_FOR_SGFIX noprint;
var CSA_Price;
by product_id;

output out= work.CSA_Percentiles_Prod

pctlpre= P
pctlpts= 40 to 60 by 10;

run;

1 个答案:

答案 0 :(得分:0)

在SAS中,我的理解是诸如proc univariate之类的过程通常不会产生视图作为输出。我能想到的唯一解决方法是让您在数据步骤中复制proc逻辑并从数据步骤生成视图。你可以这样做,例如通过将变量转换为临时数组并使用pctl函数。

这是一个简单的例子:

data example /view = example;
  array _height[19]; /*Number of rows in sashelp.class dataset*/

  /*Populate array*/
  do _n_ = 1 by 1 until(eof);
    set sashelp.class end = eof;
    _height[_n_] = height;
  end;

  /*Calculate quantiles*/
  array quantiles[3] q40 q50 q60;
  array points[3] (40 50 60);
  do i = 1 to 3;
    quantiles[i] = pctl(points[i], of _height{*});
  end;

  /*Keep only the quantiles we calculated*/
  keep q40--q60;
run;

通过更多工作,您还可以使此方法按群组而不是一次性返回整个数据集的百分位数。您需要编写一个双DOW循环来执行此操作,例如:

data example;
  array _height[19];
  array quantiles[3] q40 q50 q60;
  array points[3] _temporary_ (40 50 60);

  /*Clear heights array between by groups*/
  call missing(of _height[*]);

  /*Populate heights array*/
  do _n_ = 1 by 1 until(last.sex);
    set class end = eof;
    by sex;
    _height[_n_] = height;
  end;

  /*Calculate quantiles*/
  do i = 1 to 3;
    quantiles[i] = pctl(points[i], of _height{*});
  end;

  /* Output all rows from input dataset, with by-group quantiles attached*/
  do _n_ = 1 to _n_;
    set class;
    output;
  end;
  keep name sex q40--q60;
run;
相关问题