在 sas 中选择具有较长名称的观察或行 [英] pick observation or row having longer name in sas

查看:32
本文介绍了在 sas 中选择具有较长名称的观察或行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据集

id   name          age sex
1  Murray, W       23   M
2  Bonaventure, T  24   F
3  Eberhardt, S    56   M
4  LaMance, K      78   M
5  Underwood, K    23   F

我们必须从数据集a创建数据集b

we have to create dataset b from dataset a

id   name          age sex
2  Bonaventure, T  24   F

我们必须在所有名称变量中选择名称较长的数据,因此我们必须选择名称较长的观察,以便数据集 b 只包含一个数据.

we have to select data having longer name in all name variable so we have to select the observation having longer name so dataset b contain only one data.

推荐答案

您需要首先找到所有记录的最大长度,然后将其与每个单独记录的长度进行比较.请记住,不止一个记录可以满足此标准.在你的例子中只有一个.

You need to find first the maximun length across all records and then compare it against each indiviual record's length. bear in mind that more than one record can meet this criteria. in your example is only one though.

这里是一个使用proc sql

proc sql;
create table b as 
select * from a 
    where
        length(name) = (select max(length(name) from a) ;
quit;

这篇关于在 sas 中选择具有较长名称的观察或行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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