1

我想知道是否可以对尚未合并到当前数据集的数据集执行条件子句?

“如果受试者在 DEMOG 中具有非缺失的 SUBJNO 并且在 DOSEADM 中具有至少一个非缺失的 RANDSEQ 并且 SUBJNO 不包含在 SFL 中,则 RAND = 1。”

以上是需要的。

为清楚起见,数据集是 DEMOG、DOSEADM 和 SFL。SFL 是一个筛选失败的数据集,因此它只会包含筛选失败的主题。DEMOG 是一个人口统计数据集,仅包含通过筛选的主题。DOSEADM 是一个剂量管理数据集。

在 OOP 伪代码中,它可能类似于以下内容。

如果 ^missing(DEMOG.subjno) 和 nmiss(DOSEADM.randseq) >=1 并且 SUBJNO ^in(SFL.SUBJNO) 然后标记。

是否可以在 SAS 中进行类似的操作?或者是否可以在 SAS 中的 SQL 中做类似的事情?

4

2 回答 2

1

我将为数据集中的主题创建格式。例如,你可以拿 DEMOG:

data for_fmt; *create a dataset for formats, name it something relevant to you;
set dmog;
start=subjno;
label='1';
fmtname='DEMOG'; *include $ in front if subjno is a character variable;
output;
if _n_ = 1 then do;
hlo='o';
start=.; *or ' ' if char;
label='0';
output;
run;

proc format cntlin=for_fmt; *load to formats library;
quit;

data want;
set have;
if put(subjno,DEMOG.)='1' then output; *keep only DEMOG subjects;
run;

您可以对每个数据集执行此操作(DOSEADM 条件在这里似乎也很容易实现),然后使用这三种格式。

于 2013-11-06T14:59:52.817 回答
1

我想我理解你要正确的第二个条件,但如果我错了,请澄清。

您可以使用 proc sql 中的子查询来执行此操作。每个子查询必须只返回一列数据,然后使用 case 子句可以测试您的 SUBJNO 是否在每个条件中,如果全部为真则返回 1,否则返回 0。

 proc sql noprint;

    create table table_new as
    select *, case
                when SUBJNO in (select distinct SUBJNO from DEMOG where SUBJNO ne .) /*this finds where subjno not missing in DEMOG table*/
                    and SUBJNO not in (select distinct SUBJNO from SFL) /*this finds where subjno not in SFL table*/
                    and SUBJNO in (select distinct SUBJNO from DOSEADM where RANDSEQ = . group by SUBJNO having count(SUBJNO) > 1) /*This finds the subjno having >1 missing randseq observations*/ then 1
                else 0
                end as RAND
    from table_old
    ;
  quit;
于 2013-11-06T14:33:07.593 回答