Search
  • DD

SAS VERSUS R : USING ARRAYS

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”

0 views

Recent Posts

See All

SAS VERSUS R : USING LISTS

I've an extensive background in SAS suite of tools. But R is fairly new to me and I’ve been studying it in my spare time. I figured the best way to learn R is to compare it with SAS. I've SAS Universi

 

Subscribe Form

  • Facebook
  • Twitter
  • LinkedIn

©2020 by All About Analytics. Proudly created with Wix.com