输入/打印要登录SAS的变量的平均值

输入/打印要登录SAS的变量的平均值,sas,Sas,如何将变量的平均值打印到SAS中的日志中 data fruit; input zip fruit & $22. pounds; datalines; 10034 apples, grapes kiwi 123456 92626 oranges 97654 25414 pears apple 987654 ; 这就是我尝试过的: data _null_; set fruit; put mean(zip); run; 您可以使用以下步骤计算磅变量的平均值,然后

如何将变量的平均值打印到SAS中的日志中

data fruit;
input zip fruit & $22. pounds;
datalines;
10034 apples, grapes kiwi  123456
92626  oranges  97654
25414 pears apple      987654
;
这就是我尝试过的:

data _null_;
   set fruit;
   put mean(zip);
run;
您可以使用以下步骤计算磅变量的平均值,然后是一个例程将值分配给宏变量,最后是一个
%PUT
将其打印到日志中

proc means data=fruit;
  var pounds;
  output out=testmean mean=fruit_mean;
run;

data _null_;
  set testmean;
  call symput("fruit_avg",fruit_mean);
run;

%put mean of x is &fruit_avg;
您可以使用procsql

proc sql noprint; 
/*noprint as you don't want to print to the defined output location, just the log*/

/*format, formats the value.  into :<> puts the value into a macro variable named <>*/
select mean(zip) format=best32.
   into :zip_mean
   from fruit;

/*%put writes a message to the log*/
%put Mean of Zip: &zip_mean;
quit;

在数据步骤中,您可以使用
putlog
语句在日志上打印值。根据@cherry_bueno的回答,
putlog
版本为:

proc means data=fruit;
  var pounds;
  output out=testmean mean=fruit_mean;
run;

data _null_;
  set testmean;
  putlog 'mean of x is ' fruit_mean;
run;

不能以这种方式在PUT语句中使用函数。你一定要把它放到日志上吗?您可以运行PROC MEANS。如果您使用RTM,并且不希望R语法在SAS中工作,那么您的运气会更好。如果您正在转换到SAS,请记住,它逐行通过数据集,因此平均值函数在单行上工作,而不是在列上。R获取数据并将其视为矩阵/数组/数据帧,您可以进行矩阵运算。SAS不是这样工作的……一次一行……但它可以处理更大的数据,而不会出现问题。@data\u null\u谢谢,它不必进入日志。它只需要用最少的击键/鼠标点击量进入我的大脑:)
proc means data=fruit;
  var pounds;
  output out=testmean mean=fruit_mean;
run;

data _null_;
  set testmean;
  putlog 'mean of x is ' fruit_mean;
run;