我需要从 SAS 中删除带有空白的重复值:下面的示例数据
比赛 | 名字 | 姓氏 | 多布 | id |
---|---|---|---|---|
紫色 | 约翰 | 将会 | 220985 | 1 |
约翰 | 将会 | 220985 | 1 | |
绿色 | 唐尼 | 阿曼 | 210784 | 2 |
泰隆 | 史密斯 | 010295 | 3 | |
绿色 | 泰隆 | 史密斯 | 010295 | 3 |
我想删除具有相同 id 的空格的匹配项。有些使用 id 列删除具有空白的重复项
在 SAS 中,您可以使用 PROC SORT 和 DATA 步骤删除重复值,同时保留空白值。这是一个基于您的数据的示例:
/* Creating example dataset */
data have;
input Match $ forename $ surname $ dob id;
datalines;
purple John will 220985 1
John will 220985 1
green donny aman 210784 2
tyrone smith 010295 3
Green tyrone smith 010295 3
;
run;
/* Sorting data by ID and keeping records with blanks */
proc sort data=have out=sorted;
by id Match;
run;
/* Keeping only the first record (with blanks) for each ID */
data nodupes;
set sorted;
by id Match;
if first.id;
run;
此代码按 ID 和
Match
对数据进行排序,然后在 DATA 步骤中使用 first.id
条件仅保留每个 ID 的第一条记录。这会保留带有空白的记录,同时根据 ID 列删除重复项。根据您的实际数据集调整代码中的变量名称。