Hi,
I have been trying to define an array in SAS University Edition by using the following code :-
data arraymaking;
input height weight age @@;
array test[4] t1 t2 t3 t4 (90 80 70 70);
datalines;
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
;
proc print data=arraymaking;
var test[1] ;
run;
SAS throws an error:-
That's not how arrays work in SAS.
They are simply a method to shortcut reference the variables but it does not exist after the data step.
If you want the second entry you need to use the variable name T1, not test[1] because the TEST array does not exist in the arraymaking data set. It only has the variables included.
@lglovenish96 wrote:
Hi,
I have been trying to define an array in SAS University Edition by using the following code :-
data arraymaking;
@input height weight age @@;
array test[4] t1 t2 t3 t4 (90 80 70 70);datalines;
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
;proc print data=arraymaking;
var test[1] ;
run;
SAS throws an error:-
ERROR: Variable TEST not found.ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, /, :, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.ERROR 200-322: The symbol is not recognized and will be ignored.72 run;Can Someone tell me what i am doing wrong ? Why is SAS unable to recognise "Test" as an array?Thank You.
That's not how arrays work in SAS.
They are simply a method to shortcut reference the variables but it does not exist after the data step.
If you want the second entry you need to use the variable name T1, not test[1] because the TEST array does not exist in the arraymaking data set. It only has the variables included.
@lglovenish96 wrote:
Hi,
I have been trying to define an array in SAS University Edition by using the following code :-
data arraymaking;
@input height weight age @@;
array test[4] t1 t2 t3 t4 (90 80 70 70);datalines;
1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
;proc print data=arraymaking;
var test[1] ;
run;
SAS throws an error:-
ERROR: Variable TEST not found.ERROR 22-322: Syntax error, expecting one of the following: a name, ;, -, /, :, _ALL_, _CHARACTER_, _CHAR_, _NUMERIC_.ERROR 200-322: The symbol is not recognized and will be ignored.72 run;Can Someone tell me what i am doing wrong ? Why is SAS unable to recognise "Test" as an array?Thank You.
@Reeza - Okay. I understand now how to use an array. BUt can u explain to me then what is the difference between an array i defined as above and a temperory array ?
Is there any way i can use an array in a print procedure or is it not allowed in SAS?
A temporary array does not include the variables in the output, a permanent array will create the variables, if they do not already exist.
Arrays within the PRINT procedure is not supported, depending on what you're trying to do (you never explained that) there may be other options.
@lglovenish96 wrote:
@Reeza - Okay. I understand now how to use an array. BUt can u explain to me then what is the difference between an array i defined as above and a temperory array ?
Is there any way i can use an array in a print procedure or is it not allowed in SAS?
@Reeza - i was trying to print out the array in the proc print statement while making sure the variable name displayed is that of the array element assigned to the variable.
Was Studying the topic for the first time and basically just experimenting with the functionality to get a better idea of how arrays works.
Thanks a lot for your help. 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.