简体   繁体   English

SAS proc意味着创建变量

[英]SAS proc means together with creating variable

I want to do proc means on variable, which I should create in my dataset based on some other existing variables. 我想对变量执行proc手段,我应该根据其他现有变量在数据集中创建变量。 Can I manage to do this in one procedure? 我可以在一个过程中做到这一点吗?

My hopeless trial was 我绝望的审判是

data example;
do i =1 to 100;
   x=i**2;
   output;
end;
run;

proc means data = example mean;
var y = x + i;
run;

but it doesn't work. 但这不起作用。 Is there a way to do this? 有没有办法做到这一点? Thanks for any help. 谢谢你的帮助。

You could try using the PROC SQL procedure which covers most of the summary stats producible using PROC MEANS 您可以尝试使用PROC SQL过程,该过程涵盖了使用PROC MEANS产生的大多数摘要统计信息

proc sql;
select mean(x+1) as y
from example;
quit;

You could create a VIEW and do the means on that. 您可以创建一个VIEW并进行相应的处理。

data example_v/view=example_v;
set example;
y=x+i;
run;

proc means data=example_v mean;
var y;
run;

VIEW is like a dataset, except that it isn't really run until it's needed - so even if example is very large it will take no time to create the view, and then approximately the same time to run the proc means as it would otherwise have with example . VIEW就像一个数据集,只是它直到需要时才真正运行-因此,即使example很大,它也不会花费时间来创建视图,然后大约需要与其他时间运行proc meansexample

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM