Reputation: 704
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. 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.
Upvotes: -1
Views: 106
Reputation: 51601
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.
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
;
Upvotes: 2
Reputation: 3117
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. You might also want to have a deeper look at the VALIDMEMNAME= option and at Names in the SAS Language.
Upvotes: 2