Arrays in SAS

Arrays are nothing but a collection of elements of same type. We all are aware of Arrays in various object oriented languages, but unlike in SAS, Arrays doesnot hold any value. SAS uses arrays as reference variable in programming. 

Syntax of Arrays: Array in SAS is declared as  
  
                         array man{10} man1 man2 man3 . . . . . man10;

Array names follow same rules as for SAS variable names. Name is followed by a bracket {} or [] & value inside bracket is a subscript.

A SAS array must contain all character or numeric variable. A character array can be declared as 

                          array  month{12} $3. JAN-DEC;

Usage of Array: 
1).  Arrays can be used to set missing values for any other values like 999 ,0 ,???, NA etc.
2). Converting all character values to lower case, upper case, or propercase.
3). To Create new variables.


_character_ is used with array if we don't know the names of character type to be included in array.

                         array chars{*}  $10. _character_;

A ' * ' is used when we need SAS to calculate the no. of elements in array. Like we mentioned in above array declaration, in which a charcter array is  created.

dim(chars) is used to calculate no. of elements to be passed as an argument in some loop or conditional statement.

If we don't mention any element names in array then SAS consider array name with subscript as element name. For example suppose an array for employees is created.

                         array employee {10} 

Then its elements will be    employee1, employee2, employee3, employee4.... employee10.


                                                                            

No comments:

Post a Comment

My First SAS Program