具有重复 ID 值的 proc 转置 [英] proc transpose with duplicate ID values

查看:25
本文介绍了具有重复 ID 值的 proc 转置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关 SAS 中 proc 转置过程的帮助.我的代码最初是:

I need help with proc transpose procedure in SAS. My code initially was:

proc transpose data=temp out=temp1; 
by patid;
var text;
Id datanumber;
run;

这给了我错误ID 值"在同一个 BY 组中出现两次".我将代码修改为:

This gave me error "The ID value " " occurs twice in the same BY group". I modified the code to this:

proc sort data = temp; 
by patid text datanumber; 
run;

data temp; 
set temp by patid text datanumber; 
if first.datanunmber then n = 0; 
n+1; 
run;

proc sort data = temp; 
by patid text datanumber n; 
run;

proc transpose out=temp1 (drop=n) let;
by patid;
var text;
id datanumber;
run;

这给了我错误:变量 n 无法识别.添加一个 let 选项会导致很多错误在同一个 BY 组中出现两次".我想保留所有 id 值.

This is giving me error: variable n is not recognized. Adding a let option is giving a lot of error "occurs twice in the same BY group". I want to keep all id values.

请帮帮我.

数据示例:部分文字

推荐答案

当您收到该错误时,它告诉您您尝试创建的一个或多个变量有多个数据点.如果您将let"添加到 proc 转置行,SAS 可以强制转置并删除额外的数据点.

When you get that error it is telling you that you have multiple data points for one or more variables that you are trying to create. SAS can force the transpose and delete the extra datapoints if you add "let" to the proc transpose line.

这篇关于具有重复 ID 值的 proc 转置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆