PROC SQL与两个where语句合并并在单个数据集中

时间:2017-11-13 17:04:30

标签: sas

data a;
set b1(where=(PARAMCD='ABC') rename=(aval=abc) in=a) b1(where=(PARAMCD='CDE') rename=(aval=cde));
by usubjid  AVISITN;
if a;
PARAMCD="ASD";

AVAL=mean(abc,cde);
run;

我在SAS中有一个数据集,其中有几个参数我需要过滤这些值的两个参数和平均值。我需要创建一个proc sql语法来解决合并问题。

1 个答案:

答案 0 :(得分:1)

看起来你只想加入一张桌子。尝试这样的事情。

df = structure(list(ID = c(1, 2, 3), DV1_A = c(1, NA, NA), DV1_B = c(NA, 
4, NA), DV1_C = c(NA, NA, 5), DV2_A = c(3, NA, NA), DV2_B = c(NA, 
3, NA), DV2_C = c(NA, NA, 5), FACT = structure(1:3, .Label = c("A", 
"B", "C"), class = "factor")), .Names = c("ID", "DV1_A", "DV1_B", 
"DV1_C", "DV2_A", "DV2_B", "DV2_C", "FACT"), row.names = c(NA, 
-3L), class = "data.frame")

或者您可以使用子查询来复制where = dataset选项。

proc sql ;
create table a as
  select a.usubjid
       , a.avisitn
       , a.aval as abc
       , b.aval as cde
       , mean(a.aval,b.aval) as aval
  from b1 a
  left join b1 b
  on a.usubjid = b.usubjid
  and a.avisitn = b.avisitn
  and a.paramcd='ABC'
  and b.paramcd='CDE'
;
quit;