Quantcast
Channel: SAS versus R in Analytics
Viewing all articles
Browse latest Browse all 17

SAS versus R : using arrays

$
0
0

In a general programming language, an array is considered to be a data structure which stores variables of similar data type. In SAS, this is not the case. An array is only a compile-time statement and thus, it will not exist outside the scope of the calling data step.

In R, arrays are created from a data structure called vectors using a c() function. This function combines values of similar data types. Once a vector is created, the vector name is passed as a value to an “array” function.

Example in SAS

data temp;

array color_array{3} $8 ( ‘Purple’, ‘Brown’, ‘Red’ );
putlog “Second element in the array is ” color_array{2};

run;

Example in R

> colors <- c( ‘Purple’, ‘Brown’, ‘Red’)
> print ( colors )
[1] “Purple” “Brown” “Red”
> color_array <- array ( colors )
> print ( class ( color_array ))
[1] “array”
> print( color_array[2] )
[1] “Brown”

 



Viewing all articles
Browse latest Browse all 17

Trending Articles