具有重复 ID 值的 proc 转置
我需要 SAS 中 proc 转置过程的帮助。我的代码最初是:
proc transpose data=temp out=temp1;
by patid;
var text;
Id datanumber;
run;
这给了我错误“ID 值“”在同一个 BY 组中出现两次”。我将代码修改为:
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 值。
请帮助我。
数据示例: 耐心的文本
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;
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;
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.
Please help me in this.
Data Example:
Patid Text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当您收到该错误时,它告诉您您尝试创建的一个或多个变量有多个数据点。如果您将“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.
您的数据可能不是唯一的?我创建了一个数据集(具有 patid 和 datanumber 的唯一值)并且转置有效:
我的建议是忘记“n”修复并专注于使 patid 和 datanumber 的数据唯一,一个肮脏的方法是:
在开始时你的代码..
Your data is possibly not unique? I created a dataset (with unique values of patid and datanumber) and the transpose works:
my recommendation would be to forget the 'n' fix and focus on making the data unique for patid and datanumber, a dirty approach would be:
at the start of your code..
尝试按 patid 文本 n 数据编号(n 在数据编号之前)对数据集进行排序。
Try to sort your dataset by patid text n datanumber, (n before datanumber).
尝试按 patid n datanumber(n 在 datanumber 之前)对数据集进行排序。和 proc 转置“by patib n”;
Try to sort your dataset by patid n datanumber, (n before datanumber). and proc transpose "by patib n ";
如果数据不唯一,另一种解决方法是添加行号字段,以便有一个可以排序和分组的唯一标识符。
Another way to address, if data is not unique, is to add a row number field so that there is a unique identifier you can sort and group by.