在SAS中使PROC MEANS语句产生变量而不是数据集 [英] Making the PROC MEANS statement in SAS produce a variable instead of a dataset

查看:393
本文介绍了在SAS中使PROC MEANS语句产生变量而不是数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取列中所有值的总和(以下代码中的"var1").据我所确定,这是按照以下步骤进行的:

I need to obtain the sum of all the values in a column ("var1" in the code below). As far as I could determine, this is done as follows:

proc means data = somedata sum var1;
output out = sumtable sum = sum;
run; 

我要在下一步中用作变量的总和.是否可以使上面的OUTPUT语句将总和存储在新变量中,而不是将其写入整个新数据集中?如果是这样,它的语法是什么?

The sum I want to use as a variable in the next step. Is it possible to have the OUTPUT statement above store the sum in a new variable instead of writing it to a whole new dataset? If so, what is the syntax for this?

推荐答案

总之,没有.您可以按照Reeza的建议将值作为文本字符串存储到宏变量中,但是如果要将其存储为变量,则该变量必须位于数据集中.

In a word, no. You could store the value as a text string into a macro variable as Reeza suggests, but if you want to store it as a variable then the variable needs to be in a dataset.

如果您想将该变量用于某些用途,则不难将其带回到将来的数据步骤中.只需引用存储它的数据集即可.

It is not hard to bring that variable back into a future data step if you want to use it for something. Just reference the dataset where it is stored.

proc summary data=sashelp.class ;
  var height weight ;
  output out=class_summary sum=total_height total_weight;
run;
data new ;
  set sashelp.class;
  if _n_=1 then set class_summary;
  fraction_of_total_wt = weight / total_weight;
  fraction_of_total_ht = height / total_height;
run;

这篇关于在SAS中使PROC MEANS语句产生变量而不是数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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