SlideShare a Scribd company logo
1 of 7
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

What's hot

Base SAS Full Sample Paper
Base SAS Full Sample Paper Base SAS Full Sample Paper
Base SAS Full Sample Paper Jimmy Rana
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheetAli Ajouz
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questionsDr P Deepak
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2venkatam
 
Introduction to SAS Data Set Options
Introduction to SAS Data Set OptionsIntroduction to SAS Data Set Options
Introduction to SAS Data Set OptionsMark Tabladillo
 
Understanding sas data step processing.
Understanding sas data step processing.Understanding sas data step processing.
Understanding sas data step processing.Ravi Mandal, MBA
 
Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Mark Tabladillo
 
A Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureA Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureYesAnalytics
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sashalasti
 
Where Vs If Statement
Where Vs If StatementWhere Vs If Statement
Where Vs If StatementSunil Gupta
 
Base SAS Exam Questions
Base SAS Exam QuestionsBase SAS Exam Questions
Base SAS Exam Questionsguestc45097
 
SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1venkatam
 

What's hot (20)

SAS Proc SQL
SAS Proc SQLSAS Proc SQL
SAS Proc SQL
 
Sas cheat
Sas cheatSas cheat
Sas cheat
 
C Basics
C BasicsC Basics
C Basics
 
SAS Macros
SAS MacrosSAS Macros
SAS Macros
 
Base SAS Full Sample Paper
Base SAS Full Sample Paper Base SAS Full Sample Paper
Base SAS Full Sample Paper
 
SAS cheat sheet
SAS cheat sheetSAS cheat sheet
SAS cheat sheet
 
Base sas interview questions
Base sas interview questionsBase sas interview questions
Base sas interview questions
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
 
Introduction to SAS Data Set Options
Introduction to SAS Data Set OptionsIntroduction to SAS Data Set Options
Introduction to SAS Data Set Options
 
Understanding sas data step processing.
Understanding sas data step processing.Understanding sas data step processing.
Understanding sas data step processing.
 
SAS Macro
SAS MacroSAS Macro
SAS Macro
 
Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3Proc SQL in SAS Enterprise Guide 4.3
Proc SQL in SAS Enterprise Guide 4.3
 
A Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report ProcedureA Step-By-Step Introduction to SAS Report Procedure
A Step-By-Step Introduction to SAS Report Procedure
 
Introduction To Sas
Introduction To SasIntroduction To Sas
Introduction To Sas
 
Where Vs If Statement
Where Vs If StatementWhere Vs If Statement
Where Vs If Statement
 
Proc report
Proc reportProc report
Proc report
 
Base SAS Exam Questions
Base SAS Exam QuestionsBase SAS Exam Questions
Base SAS Exam Questions
 
Java arrays
Java arraysJava arrays
Java arrays
 
SAS Macros part 4.1
SAS Macros part 4.1SAS Macros part 4.1
SAS Macros part 4.1
 
Java collections
Java collectionsJava collections
Java collections
 

Viewers also liked

ITIL Foundation Certificate in IT Service Management
ITIL Foundation Certificate in IT Service ManagementITIL Foundation Certificate in IT Service Management
ITIL Foundation Certificate in IT Service ManagementRavi Mandal, MBA
 
Conditional statements in sas
Conditional statements in sasConditional statements in sas
Conditional statements in sasvenkatam
 
Introduction about analytics with sas+r programming.
Introduction about analytics with sas+r programming.Introduction about analytics with sas+r programming.
Introduction about analytics with sas+r programming.Ravi Mandal, MBA
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
 

Viewers also liked (8)

ITIL Foundation Certificate in IT Service Management
ITIL Foundation Certificate in IT Service ManagementITIL Foundation Certificate in IT Service Management
ITIL Foundation Certificate in IT Service Management
 
2 unit ie& v
2 unit  ie& v2 unit  ie& v
2 unit ie& v
 
Cluster analysis
Cluster analysisCluster analysis
Cluster analysis
 
Certificate
CertificateCertificate
Certificate
 
Conditional statements in sas
Conditional statements in sasConditional statements in sas
Conditional statements in sas
 
Introduction about analytics with sas+r programming.
Introduction about analytics with sas+r programming.Introduction about analytics with sas+r programming.
Introduction about analytics with sas+r programming.
 
INDIAN ETHOS 1
INDIAN ETHOS 1INDIAN ETHOS 1
INDIAN ETHOS 1
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Similar to Sas array statement

Similar to Sas array statement (20)

ARRAYS.ppt
ARRAYS.pptARRAYS.ppt
ARRAYS.ppt
 
Array lecture
Array lectureArray lecture
Array lecture
 
LectureNotes-05-DSA
LectureNotes-05-DSALectureNotes-05-DSA
LectureNotes-05-DSA
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
Unit 2
Unit 2Unit 2
Unit 2
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Java arrays (1)
Java arrays (1)Java arrays (1)
Java arrays (1)
 
9
99
9
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Lecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdfLecture 2.8 Arrays.pdf
Lecture 2.8 Arrays.pdf
 
BAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 LectureBAS 150 Lesson 6 Lecture
BAS 150 Lesson 6 Lecture
 
Plsql arrays
Plsql arraysPlsql arrays
Plsql arrays
 
Ch08
Ch08Ch08
Ch08
 
3.ArraysandPointers.pptx
3.ArraysandPointers.pptx3.ArraysandPointers.pptx
3.ArraysandPointers.pptx
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 

Recently uploaded

Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queensdataanalyticsqueen03
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一
办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一
办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一F La
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 

Recently uploaded (20)

Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queens
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一
办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一
办理(UWIC毕业证书)英国卡迪夫城市大学毕业证成绩单原版一比一
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 

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