基于值添加新列(Adding a new column based on values)

编程入门 行业动态 更新时间:2024-10-24 02:36:18
基于值添加新列(Adding a new column based on values)

我有以下示例数据:

data weight_club; input IdNumber 1-4 Name $ 6-24 Team $ StartWeight EndWeight; Loss = StartWeight - EndWeight; datalines; 1023 David Shaw red 189 165 1049 Amelia Serrano yellow 145 124 1219 Alan Nance purple 210 192 1246 Ravi Sinha yellow 194 177 1078 Ashley McKnight green 127 118 ;

我现在想要做的是以下几点:

用颜色创建两个列表(fe,list1 =“red”,“yellow”和list2 =“purple”和“green”) 根据是否在列表1和列表2中分类记录并添加新列。

所以伪代码是这样的:

'Set new category called class If item is in list1 then class = 1 Else if item is in list2 then class = 2 Else class = 3

关于如何最有效地做到这一点的任何想法?

I have the following sample data:

data weight_club; input IdNumber 1-4 Name $ 6-24 Team $ StartWeight EndWeight; Loss = StartWeight - EndWeight; datalines; 1023 David Shaw red 189 165 1049 Amelia Serrano yellow 145 124 1219 Alan Nance purple 210 192 1246 Ravi Sinha yellow 194 177 1078 Ashley McKnight green 127 118 ;

What I would like to do now is the following:

Create two lists with colours (fe, list1 = "red" and "yellow" and list2 = "purple" and "green") Classify the records according to whether or not they are in list1 and list2 and add a new column.

So the pseudo code is like this:

'Set new category called class If item is in list1 then class = 1 Else if item is in list2 then class = 2 Else class = 3

Any thoughts on how I can do this most effciently?

最满意答案

你的伪代码几乎就是它。

If item is in ('red' 'yellow') then class = 1; Else if item is in ('purple' 'green') then class = 2; Else class = 3;

这真是一个查找,所以他们有很多其他的方法。 我通常推荐的还有Proc格式,虽然在这种简单的情况下,我不确定是否有任何收益。

Proc format; Value $ colour_cat 'red', 'yellow' = 1 'purple', 'green' = 2 Other = 3; Run;

然后在数据/ SQL中可以使用以下任一项。

*actual conversion; Category = put(colour, $colour_cat.); * change display only; Format colour $colour_cat.;

Your pseudocode is almost exactly it.

If item is in ('red' 'yellow') then class = 1; Else if item is in ('purple' 'green') then class = 2; Else class = 3;

This is really a lookup, so their are many other methods. One I usually recommend as well is Proc format, though in a simplistic case like this I'm not sure of any gains.

Proc format; Value $ colour_cat 'red', 'yellow' = 1 'purple', 'green' = 2 Other = 3; Run;

And then in a data/SQL either of the following can be used.

*actual conversion; Category = put(colour, $colour_cat.); * change display only; Format colour $colour_cat.;

更多推荐

本文发布于:2023-07-27 17:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1293577.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:column   Adding   values   based

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!