简体   繁体   English

如何在 SAS 中使用实数/数值作为变量?

[英]How to use real numbers/numeric values as variables in SAS?

I would like to know how to use variables that are real numbers as variables name.我想知道如何使用实数变量作为变量名。 For instance例如

data have;
input 
Y     0.133      0.124      0.1242    0.142 ;
datalines;
123  121     214     241   241
431  143     141     241   124
214  124     214     142   241
531  432     134     412   124
243  124     134     134   123
;

proc transpose data=have out=tall (rename=col1=x);
  by y notsorted;
  var /* what should I put here? */;
run;

ods html file='hbox-plot.html';

proc sgplot data=tall;
   hbox x / category=y;
   yaxis type=linear;
run;

ods html close;

Trying to use the real values in var selection in the proc transponse I have got the error: syntax error.尝试在 proc transponse 中使用 var selection 中的实际值时出现错误:语法错误。 My expected output would be box plots, where on the x axis I have information based on the real values above, and on the y axis information on y.我预期的 output 将是箱线图,在 x 轴上我有基于上述实际值的信息,在 y 轴上关于 y 的信息。

Not really sure what you are trying to achieve but if you want to get rid of that syntax error due to the variable names, the following should work.不太确定您要实现什么,但是如果您想摆脱由于变量名而导致的语法错误,以下应该可以工作。

data have;
input 
Y "0.133"n "0.124"n "0.1242"n "0.142"n ;
datalines;
123  121     214     241   241
431  143     141     241   124
214  124     214     142   241
531  432     134     412   124
243  124     134     134   123
;

proc transpose data=have out=tall(rename=(col1=x _name_=var));
  by y notsorted;
  var "0.133"n "0.124"n "0.1242"n "0.142"n;
run;

The letter "n" is used to distinguish between a quoted string and a name literal value.字母“n”用于区分带引号的字符串和名称文字值。 You might also want to have a deeper look at the VALIDMEMNAME= option and at Names in the SAS Language .您可能还想深入了解VALIDMEMNAME=选项和SAS 语言中的名称

Don't put data into names.不要将数据放入名称中。 Instead of trying to make a variable named 0.133 put the value of 0.133 into a variable.不要尝试创建一个名为 0.133 的变量,而是将 0.133 的值放入一个变量中。

The other way to represent a grid of data is to have one observation for each cell with three variables.表示数据网格的另一种方法是对每个具有三个变量的单元格进行一个观察。 One for the vertical index, one for the horizontal index and the third to have the value stored in the cell at the intersection of the two.一个用于垂直索引,一个用于水平索引,第三个用于将值存储在两者交叉处的单元格中。

data have;
  input y @;
  do x=0.133,0.124,0.1242,0.142 ;
    input z @;
    output;
  end;
datalines;
123  121     214     241   241
431  143     141     241   124
214  124     214     142   241
531  432     134     412   124
243  124     134     134   123
;

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

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