Updated March 16, 2023
Introduction to SAS Array
The arrays in SAS are mainly used to store and retrieve the values using the index value format to represent the data location. Depending upon the reserved memory areas, array-name is defined as the array followed by the same set of rules applicable for the variable names subscript is the number of input values used in the array.
What is SAS Array?
It is the most important and convenient way for temporary usage. It identifies the variable groups with data processing along with the data steps, which the data programmers already define for performing the same number of tasks with related variables using the array elements that define the name of the elements. It has been fetched, and select the data range of the elements with all sets of variables that started with the start and end type of variables of the same type.
We can create the SAS of the elements with a specified set of arrays on the SAS code. Array statement will use and start the Array keyword for declaring the SAS to define the new array for the length and some additional parameters. But the array must be the valid SAS name followed by the maximum set of characters like 32, and it starts with the letter or underscore of the subsequent characters of alphanumeric characters. It does not contain the blank value nor a special set of characters except the underscores and other special characters. So that besides, the array name with a valid SAS name can’t have the same name for any of the variables on the dataset and should not give the array with the same set of names for the existing SAS function.
How to Create and Use SAS Array?
Mainly SAS arrays are used for storing and retrieving the datas with a series set of values of the index range. The index represents the location and reserves the shared memory areas for the subscript of the optional parameters for storing the character set of values. The variable set of lists is used in the optional set of variables stored in the placeholders for array values that can be set as the actual values stored in the array for a declaration from the file format for both reads and write operations on the data line. The array statement mainly creates the array in SAS for all the statements, starting with the array keyword, then using the array name, length, and some additional optional parameters.
Array length is the mandatory part and concept of the number of elements that must be enclosed with an open and closed set of brackets or other operators like open and closed parenthesis. Array length and Array type should be mandatory fields for the array statement with a specified set of elements to determine the number of elements specified for the array elements. The analytics will take more time for GUI advantage and applications like six sigma, designs and other quality controls, engineering, and scientific analysis. It is one platform-independent, so it runs on any operating system, either Linux, Windows and Solaris, mac os, etc. Elements length with the default set of characters for the numeric set of array elements stored with the data information at almost eight sets of characters. Statistical Analysis Software was used for data management software and other business intelligence.
The data step programmers will always use the arrays with their codes more frequently with fewer errors and prone jobs. Its revenue and mainly expense are the data set containing twice a year in the variables for revenues and expenses in the incoming month. As the number of data increases, more statements are required to calculate monthly income. We can get the result from the previous one, which will affect the prone type of jobs. The arrays can be mainly called for data increases and growth for more statements that can be required for net income in each month.
The basic syntax for the array is below:
Syntax:
ARRAY array-name[];
The above code syntax is the array statement which consists of the ARRAY keyword with pair of parentheses(), braces(), and square brackets[] for n number of variables or elements in the associated array.
SAS cannot be determined with the variable month until running the process in run time for the syntax.
Steps to Create SAS and Arrays
Given below are the steps to create SAS and Arrays:
1. Goto Studying SAS Demand for Academics(ODA) mainly provides students and professors free access to the SAS Studio via web-based browsers.
2. https://welcome.oda.sas.com/login.
3. Register the form using the Don’t have a SAS Profile option.
4. The Pop up is open, and select the Create Profile option; it navigates to another web page like the one below.
5. https://www.sas.com/profile/ui/#/create.
6. Fill in all the required details and save it will create the SAS Profile for the specific user.
7. I have created a Profile already and signed it below.
8. https://welcome.oda.sas.com/home.
9. Goto Applications and select SAS Studio.
10. It will navigate to other web pages like the one below.
11. https://odamid-apse1-2.oda.sas.com/SASStudio/mainlocale=en_US&zone=GMT%252B05%253A30&ticket=ST-77594-c3ENcyLUdJPdBC0tOV6C-cas.
12. Next, we need to use the codes like the below example and run them to get the output result like the screenshot below.
Examples of SAS Array
Different examples are mentioned below
Example #1
Code:
DATA firstarray;
INPUT in1 $ in2 $ in3 $ in4 $ in5 $;
ARRAY inps(5) $ in1-in5;
res = in1||'+'||in2 ||'+'||in3;
DATALINES;
Welcome To My Domain have a nice day
;
RUN;
PROC PRINT DATA = firstarray;
RUN;
Output:
- In the above example, we declared the Input as the array format with string type.
- Then we declared Array input with index range values.
- We used res as the variable to perform the arithmetic, or other user operations concatenate operations.
- Initially, we declare the firstarray as the variable to be started.
- After execution, the DATALINES will be printed on the required array index tables.
Example #2
Code:
DATA second;
INPUT X1 X2 X3 X4;
ARRAY ar(4) X1-X4;
ARRAY days(4) X1-X4;
out1 = SUM(OF ar(*));
out2 = MEAN(OF ar(*));
out3 = MIN(OF ar(*));
DATALINES;
41 42 43 44
51 52 53 54
IF 'Sunday' IN days THEN Leave = 'Yes';ELSE Leave = 'No';
DATALINES;
Sunday Monday Tuesday Wednesday
;
RUN;
PROC PRINT DATA = second;
RUN;
Output:
- We followed the same procedure as the previous example in the second example.
- Here Additionally, performed the Arithmetic and Aggregate functions of the array elements with the sequence index ranges.
- We started the SUM(), MEAN(), and MIN() operations for performing the DATALINES operations.
- It will be printed on the console and stored as table datas.
Conclusion
Generally, when we work with a set or group of datas that are exactly similar to one another, it means the duplicated things that will be performed in the specific or common operations in the application. With significant time the datas will be reduced in the number of lines of codes to get the result with an additional task.
Recommended Articles
This is a guide to SAS Array. Here we discuss the introduction, Steps to create, and how to create and use a SAS array with examples. You may also have a look at the following articles to learn more –