SlideShare a Scribd company logo
SAS ARRAY Statement
A set of variables grouped together for the duration of a data step by being given a name in
an ARRAY statement
4/18/2015 Array Statement 1
Syntax
ARRAY array-name { subscript } <$><length>
<array-elements> <(initial-value-list)>;
array-name
specifies the name of the array
Restriction : Array-name must be a SAS name that is not the name of a SAS variable in the same DATA step.
CAUTION:
Using the name of a SAS function as an array name can cause unpredictable results.
If you inadvertently use a function name as the name of the array, SAS treats parenthetical references that involve the name as array
references, not function references, for the duration of the DATA step. A warning message is written to the SAS log.
{subscript}
describes the number and arrangement of elements in the array by using an asterisk, a number, or a range of numbers. Subscript has one of
these forms:
{dimension-size(s)}
specifies the number of elements in each dimension of the array. Dimension-size is a numeric representation of either the number of elements in
a one-dimensional array or the number of elements in each dimension of a multidimensional array.
You can enclose the subscript in braces ({}), brackets ( [ ] ) or parentheses (( )).
{<lower :>upper<, ...<lower :> upper>}
are the bounds of each dimension of an array, where lower is the lower bound of that dimension and upper is the upper bound.
{*} specifies that SAS is to determine the subscript by counting the variables in the array. When you specify the asterisk, also include array-
elements.
Restriction: You cannot use the asterisk with _TEMPORARY_ arrays or when you define a multidimensional array.
Arguments
$ specifies that the elements in the array are character elements.
4/18/2015 Array Statement 2
Syntax
ARRAY array-name { subscript } <$><length>
<array-elements> <(initial-value-list)>;
length
specifies the length of elements in the array that have not been previously assigned a length.
array-elements
specifies the names of the elements that make up the array. Array-elements must be either all numeric or all character, and they can be listed in
any order. The elements can be
variables
lists variable names.
These SAS variable lists enable you to reference variables that have been previously defined in the same DATA step:
_NUMERIC_
specifies all numeric variables.
_CHARACTER_
specifies all character variables.
_TEMPORARY_
creates a list of temporary data elements.
Temporary data elements can be numeric or character.
• Temporary data elements behave like DATA step variables with these exceptions:
• They do not have names. Refer to temporary data elements by the array name and dimension.
• They do not appear in the output data set.
• You cannot use the special subscript asterisk (*) to refer to all the elements.
• Temporary data element values are always automatically retained, rather than being reset to missing at the beginning of the next
iteration of the DATA step.
4/18/2015 Array Statement 3
(initial-value-list)
gives initial values for the corresponding elements in the array. The values for elements can be numbers or character strings. You must enclose all
character strings in quotation marks. To specify one or more initial values directly, use the following format:
The following examples show how to use the iteration factor and nested sub lists. All of these ARRAY statements contain the same initial value list:
•ARRAY x{10} x1-x10 (10*5);
•ARRAY x{10} x1-x10 (5*(5 5));
•ARRAY x{10} x1-x10 (5 5 3*(5 5) 5 5);
•ARRAY x{10} x1-x10 (2*(5 5) 5 5 2*(5 5));
•ARRAY x{10} x1-x10 (2*(5 2*(5 5)));
Syntax
ARRAY array-name { subscript } <$><length>
<array-elements> <(initial-value-list)>;
Details
The ARRAY statement defines a set of elements that you plan to process as a group. You refer to elements of the array by the array name
and subscript. Because you usually want to process more than one element in an array, arrays are often referenced within DO groups.
Comparisons
• Arrays in the SAS language are different from arrays in many other languages. A SAS array is simply a convenient way of temporarily
identifying a group of variables. It is not a data structure, and array-name is not a variable.
• An ARRAY statement defines an array. An array reference uses an array element in a program statement.
4/18/2015 Array Statement 4
Examples
Example 1: Defining Arrays
•array rain {5} janr febr marr aprr mayr;
•array days{7} d1-d7;
•array month{*} jan feb jul oct nov;
•array x{*} _NUMERIC_;
•array qbx{10};
•array meal{3};
Example 2: Assigning Initial
Numeric Values
•array test{4} t1 t2 t3 t4 (90 80 70 70);
•array test{4} t1-t4 (90 80 2*70);
•array test{4} _TEMPORARY_ (90 80 70 70);
Example 3: Defining Initial
Character Values
•array test2{*} $ a1 a2 a3 ('a','b','c');
Example 4: Defining More
Advanced Arrays
•array new{2:5} green jacobs denato fetzer;
•array x{5,3} score1-score15;
•array test{3:4,3:7} test1-test10;
•array temp{0:999} _TEMPORARY_;
•array x{10} (2*1:5);
4/18/2015 Array Statement 5
Example 5: Creating a Range of Variable Names That
Have Leading Zeros
The following example shows that you can create a range of variable names that have leading zeros. Each
variable name has a length of three characters, and the names sort correctly (A01, A02, ... A10). Without
leading zeros, the variable names would sort in the following order: A1, A10, A2, ... A9.
options pageno=1 nodate ps=64 ls=80;
data test (drop=i);
array a(10) A01-A10;
do i=1 to 10;
a(i)=i; end;
run;
proc print noobs data=test;
run;
4/18/2015 Array Statement 6
4/18/2015 Array Statement 7
Questions

More Related Content

DOCX
SAS Programming Notes
Gnana Murthy A
 
PPT
Arrays in SAS
guest2160992
 
DOCX
Base sas interview questions
Dr P Deepak
 
PPT
Basics Of SAS Programming Language
guest2160992
 
PPT
SAS Macros part 2
venkatam
 
PPT
SAS Macros part 1
venkatam
 
PPT
Finding everything about findings about (fa)
Ram Gali
 
PPT
Conditional statements in sas
venkatam
 
SAS Programming Notes
Gnana Murthy A
 
Arrays in SAS
guest2160992
 
Base sas interview questions
Dr P Deepak
 
Basics Of SAS Programming Language
guest2160992
 
SAS Macros part 2
venkatam
 
SAS Macros part 1
venkatam
 
Finding everything about findings about (fa)
Ram Gali
 
Conditional statements in sas
venkatam
 

What's hot (20)

PPT
CDISC SDTM Domain Presentation
Ankur Sharma
 
PPT
SAS Proc SQL
guest2160992
 
PPT
SAS Macros part 3
venkatam
 
PPT
Where Vs If Statement
Sunil Gupta
 
PPT
Data Match Merging in SAS
guest2160992
 
PPTX
Metamorphosis of pk data
Dr Shanmugavel S Sundaram
 
PDF
Learning SAS by Example -A Programmer’s Guide by Ron CodySolution
Vibeesh CS
 
PPT
Base SAS Statistics Procedures
guest2160992
 
PPTX
Tutorial on developing a Solr search component plugin
searchbox-com
 
PDF
SAS Ron Cody Solutions for even Number problems from Chapter 7 to 15
Ayapparaj SKS
 
PDF
SAS Internal Training
Amrih Muktiaji
 
PPTX
PL/SQL All the Things in Oracle SQL Developer
Jeff Smith
 
PDF
ADaM
ssuser660bb1
 
PDF
Drug Registration in GCC (Gulf Cooperation Council) - by Akshay Anand
Akshay Anand
 
PPTX
Advancing SDTM annotation through automation Anja Kreis AbbVie.pptx
VenuYadav26
 
PPTX
ADaM - Where Do I Start?
Dr.Sangram Parbhane
 
PPTX
Coding standards
BishalAryal8
 
PDF
Base SAS Exam Questions
guestc45097
 
PDF
Sas cheat
imaduddin91
 
CDISC SDTM Domain Presentation
Ankur Sharma
 
SAS Proc SQL
guest2160992
 
SAS Macros part 3
venkatam
 
Where Vs If Statement
Sunil Gupta
 
Data Match Merging in SAS
guest2160992
 
Metamorphosis of pk data
Dr Shanmugavel S Sundaram
 
Learning SAS by Example -A Programmer’s Guide by Ron CodySolution
Vibeesh CS
 
Base SAS Statistics Procedures
guest2160992
 
Tutorial on developing a Solr search component plugin
searchbox-com
 
SAS Ron Cody Solutions for even Number problems from Chapter 7 to 15
Ayapparaj SKS
 
SAS Internal Training
Amrih Muktiaji
 
PL/SQL All the Things in Oracle SQL Developer
Jeff Smith
 
Drug Registration in GCC (Gulf Cooperation Council) - by Akshay Anand
Akshay Anand
 
Advancing SDTM annotation through automation Anja Kreis AbbVie.pptx
VenuYadav26
 
ADaM - Where Do I Start?
Dr.Sangram Parbhane
 
Coding standards
BishalAryal8
 
Base SAS Exam Questions
guestc45097
 
Sas cheat
imaduddin91
 
Ad

Viewers also liked (8)

PDF
ITIL Foundation Certificate in IT Service Management
Ravi Mandal, MBA
 
DOC
2 unit ie& v
Ravi Mandal, MBA
 
PDF
Cluster analysis
Ravi Mandal, MBA
 
PPTX
Understanding sas data step processing.
Ravi Mandal, MBA
 
PDF
Certificate
Ravi Mandal, MBA
 
PPTX
Introduction about analytics with sas+r programming.
Ravi Mandal, MBA
 
DOC
INDIAN ETHOS 1
Ravi Mandal, MBA
 
PDF
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
Barry Feldman
 
ITIL Foundation Certificate in IT Service Management
Ravi Mandal, MBA
 
2 unit ie& v
Ravi Mandal, MBA
 
Cluster analysis
Ravi Mandal, MBA
 
Understanding sas data step processing.
Ravi Mandal, MBA
 
Certificate
Ravi Mandal, MBA
 
Introduction about analytics with sas+r programming.
Ravi Mandal, MBA
 
INDIAN ETHOS 1
Ravi Mandal, MBA
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
Barry Feldman
 
Ad

Similar to Sas array statement (20)

PPTX
BAS 150 Lesson 6 Lecture
Wake Tech BAS
 
PDF
Introduction to sas
Ajay Ohri
 
PPT
Programming Logic and Design: Arrays
Nicole Ryan
 
PDF
Introduction to-sas-1211594349119006-8
thotakoti
 
PDF
Introduction To Sas
halasti
 
PPT
SAS Macros
guest2160992
 
PPTX
sas.pptxnbhjghjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
AfiyaSheikh2
 
PPT
BASE SAS Training presentation of coding
shamarites
 
PPT
Arrays
Juhi Kumari
 
PDF
I need help with Applied Statistics and the SAS Programming Language.pdf
Madansilks
 
PPT
Chapter 08
Terry Yoast
 
PDF
Analytics with SAS
Edureka!
 
PDF
SAS cheat sheet
Ali Ajouz
 
PPTX
SAS basics Step by step learning
Venkata Reddy Konasani
 
PPTX
Chapter12
ARAC Company
 
PPTX
BAS 150 Lesson 3 Lecture
Wake Tech BAS
 
PPT
arrayy.ppt
ssuserb82af5
 
BAS 150 Lesson 6 Lecture
Wake Tech BAS
 
Introduction to sas
Ajay Ohri
 
Programming Logic and Design: Arrays
Nicole Ryan
 
Introduction to-sas-1211594349119006-8
thotakoti
 
Introduction To Sas
halasti
 
SAS Macros
guest2160992
 
sas.pptxnbhjghjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj
AfiyaSheikh2
 
BASE SAS Training presentation of coding
shamarites
 
Arrays
Juhi Kumari
 
I need help with Applied Statistics and the SAS Programming Language.pdf
Madansilks
 
Chapter 08
Terry Yoast
 
Analytics with SAS
Edureka!
 
SAS cheat sheet
Ali Ajouz
 
SAS basics Step by step learning
Venkata Reddy Konasani
 
Chapter12
ARAC Company
 
BAS 150 Lesson 3 Lecture
Wake Tech BAS
 
arrayy.ppt
ssuserb82af5
 

Recently uploaded (20)

PDF
A Systems Thinking Approach to Algorithmic Fairness.pdf
Epistamai
 
PPTX
The whitetiger novel review for collegeassignment.pptx
DhruvPatel754154
 
PPTX
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
PDF
Chad Readey - An Independent Thinker
Chad Readey
 
PPTX
Analysis of Employee_Attrition_Presentation.pptx
AdawuRedeemer
 
PPTX
Purple and Violet Modern Marketing Presentation (1).pptx
SanthoshKumar229321
 
PDF
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
PPTX
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
PDF
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
PPT
Grade 5 PPT_Science_Q2_W6_Methods of reproduction.ppt
AaronBaluyut
 
PDF
345_IT infrastructure for business management.pdf
LEANHTRAN4
 
PPTX
Decoding Physical Presence: Unlocking Business Intelligence with Wi-Fi Analytics
meghahiremath253
 
PDF
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
PPTX
Probability systematic sampling methods.pptx
PrakashRajput19
 
PPTX
Azure Data management Engineer project.pptx
sumitmundhe77
 
PPTX
Data Security Breach: Immediate Action Plan
varmabhuvan266
 
PPTX
Web_Engineering_Assignment_Clean.pptxfor college
HUSNAINAHMAD39
 
PDF
Company Profile 2023 PT. ZEKON INDONESIA.pdf
hendranofriadi26
 
PDF
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
PPTX
Trading Procedures (1).pptxcffcdddxxddsss
garv794
 
A Systems Thinking Approach to Algorithmic Fairness.pdf
Epistamai
 
The whitetiger novel review for collegeassignment.pptx
DhruvPatel754154
 
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
Chad Readey - An Independent Thinker
Chad Readey
 
Analysis of Employee_Attrition_Presentation.pptx
AdawuRedeemer
 
Purple and Violet Modern Marketing Presentation (1).pptx
SanthoshKumar229321
 
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
Grade 5 PPT_Science_Q2_W6_Methods of reproduction.ppt
AaronBaluyut
 
345_IT infrastructure for business management.pdf
LEANHTRAN4
 
Decoding Physical Presence: Unlocking Business Intelligence with Wi-Fi Analytics
meghahiremath253
 
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
Probability systematic sampling methods.pptx
PrakashRajput19
 
Azure Data management Engineer project.pptx
sumitmundhe77
 
Data Security Breach: Immediate Action Plan
varmabhuvan266
 
Web_Engineering_Assignment_Clean.pptxfor college
HUSNAINAHMAD39
 
Company Profile 2023 PT. ZEKON INDONESIA.pdf
hendranofriadi26
 
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
Trading Procedures (1).pptxcffcdddxxddsss
garv794
 

Sas array statement

  • 1. SAS ARRAY Statement A set of variables grouped together for the duration of a data step by being given a name in an ARRAY statement 4/18/2015 Array Statement 1
  • 2. Syntax ARRAY array-name { subscript } <$><length> <array-elements> <(initial-value-list)>; array-name specifies the name of the array Restriction : Array-name must be a SAS name that is not the name of a SAS variable in the same DATA step. CAUTION: Using the name of a SAS function as an array name can cause unpredictable results. If you inadvertently use a function name as the name of the array, SAS treats parenthetical references that involve the name as array references, not function references, for the duration of the DATA step. A warning message is written to the SAS log. {subscript} describes the number and arrangement of elements in the array by using an asterisk, a number, or a range of numbers. Subscript has one of these forms: {dimension-size(s)} specifies the number of elements in each dimension of the array. Dimension-size is a numeric representation of either the number of elements in a one-dimensional array or the number of elements in each dimension of a multidimensional array. You can enclose the subscript in braces ({}), brackets ( [ ] ) or parentheses (( )). {<lower :>upper<, ...<lower :> upper>} are the bounds of each dimension of an array, where lower is the lower bound of that dimension and upper is the upper bound. {*} specifies that SAS is to determine the subscript by counting the variables in the array. When you specify the asterisk, also include array- elements. Restriction: You cannot use the asterisk with _TEMPORARY_ arrays or when you define a multidimensional array. Arguments $ specifies that the elements in the array are character elements. 4/18/2015 Array Statement 2
  • 3. Syntax ARRAY array-name { subscript } <$><length> <array-elements> <(initial-value-list)>; length specifies the length of elements in the array that have not been previously assigned a length. array-elements specifies the names of the elements that make up the array. Array-elements must be either all numeric or all character, and they can be listed in any order. The elements can be variables lists variable names. These SAS variable lists enable you to reference variables that have been previously defined in the same DATA step: _NUMERIC_ specifies all numeric variables. _CHARACTER_ specifies all character variables. _TEMPORARY_ creates a list of temporary data elements. Temporary data elements can be numeric or character. • Temporary data elements behave like DATA step variables with these exceptions: • They do not have names. Refer to temporary data elements by the array name and dimension. • They do not appear in the output data set. • You cannot use the special subscript asterisk (*) to refer to all the elements. • Temporary data element values are always automatically retained, rather than being reset to missing at the beginning of the next iteration of the DATA step. 4/18/2015 Array Statement 3
  • 4. (initial-value-list) gives initial values for the corresponding elements in the array. The values for elements can be numbers or character strings. You must enclose all character strings in quotation marks. To specify one or more initial values directly, use the following format: The following examples show how to use the iteration factor and nested sub lists. All of these ARRAY statements contain the same initial value list: •ARRAY x{10} x1-x10 (10*5); •ARRAY x{10} x1-x10 (5*(5 5)); •ARRAY x{10} x1-x10 (5 5 3*(5 5) 5 5); •ARRAY x{10} x1-x10 (2*(5 5) 5 5 2*(5 5)); •ARRAY x{10} x1-x10 (2*(5 2*(5 5))); Syntax ARRAY array-name { subscript } <$><length> <array-elements> <(initial-value-list)>; Details The ARRAY statement defines a set of elements that you plan to process as a group. You refer to elements of the array by the array name and subscript. Because you usually want to process more than one element in an array, arrays are often referenced within DO groups. Comparisons • Arrays in the SAS language are different from arrays in many other languages. A SAS array is simply a convenient way of temporarily identifying a group of variables. It is not a data structure, and array-name is not a variable. • An ARRAY statement defines an array. An array reference uses an array element in a program statement. 4/18/2015 Array Statement 4
  • 5. Examples Example 1: Defining Arrays •array rain {5} janr febr marr aprr mayr; •array days{7} d1-d7; •array month{*} jan feb jul oct nov; •array x{*} _NUMERIC_; •array qbx{10}; •array meal{3}; Example 2: Assigning Initial Numeric Values •array test{4} t1 t2 t3 t4 (90 80 70 70); •array test{4} t1-t4 (90 80 2*70); •array test{4} _TEMPORARY_ (90 80 70 70); Example 3: Defining Initial Character Values •array test2{*} $ a1 a2 a3 ('a','b','c'); Example 4: Defining More Advanced Arrays •array new{2:5} green jacobs denato fetzer; •array x{5,3} score1-score15; •array test{3:4,3:7} test1-test10; •array temp{0:999} _TEMPORARY_; •array x{10} (2*1:5); 4/18/2015 Array Statement 5
  • 6. Example 5: Creating a Range of Variable Names That Have Leading Zeros The following example shows that you can create a range of variable names that have leading zeros. Each variable name has a length of three characters, and the names sort correctly (A01, A02, ... A10). Without leading zeros, the variable names would sort in the following order: A1, A10, A2, ... A9. options pageno=1 nodate ps=64 ls=80; data test (drop=i); array a(10) A01-A10; do i=1 to 10; a(i)=i; end; run; proc print noobs data=test; run; 4/18/2015 Array Statement 6