我如何在 SAS 中进行逐行求和 [英] How do i do a row wise sum in SAS

查看:88
本文介绍了我如何在 SAS 中进行逐行求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 SAS 对数据进行逐行求和.数据文件看起来像这样

I need to do a row wise sum of data using SAS. The data file looks like this

Dress_ID    29/8/2013   31/8/2013
1006032852  2114        2274
1212192089  151         275
1190380701  6           7

我想根据 Dress_Id 对 29/8/2013 和 31/8/2013 列求和

I want to sum the columns 29/8/2013 and 31/8/2013 as per the Dress_Id

问候,

阿迪亚

推荐答案

一种方法是使用 sum(of _NUMERIC_) 函数.如果您使用它,请确保将 Dress_ID 格式化为字符变量,因为这会将所有数字变量汇总到一行中.如果向数据集中添加额外的数字字段,您也可能会遇到一些问题,但就目前而言,这应该可以解决您的问题.

One way you can do this is by using the sum(of _NUMERIC_) function. If you use this just make sure that you format Dress_ID as a character variable as this sums all numeric variables in a row. You may also run into some problems if you add additional numeric fields to you data set but as it stands now, this should solve your problems.

可以写成:

data want;
  set have;
Total = sum(of _NUMERIC_);
run;

这将在您的数据集中创建一个包含总计的列总计".

This will create a column "Total" in your data set with the totals.

这篇关于我如何在 SAS 中进行逐行求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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