BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lglovenish96
Calcite | Level 5

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.
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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.

 

 

View solution in original post

5 REPLIES 5
Reeza
Super User

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.

 

 

lglovenish96
Calcite | Level 5

@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
Super User

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? 


 

lglovenish96
Calcite | Level 5

@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. 🙂 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1065 views
  • 0 likes
  • 2 in conversation