DATA Step, Macro, Functions and more

Unable to define Arrays in SAS University Edtion

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Unable to define Arrays in SAS University Edtion

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.

Accepted Solutions
Solution
‎04-10-2018 03:55 PM
Super User
Posts: 23,663

Re: Unable to define Arrays in SAS University Edtion

[ Edited ]
Posted in reply to lglovenish96

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


All Replies
Solution
‎04-10-2018 03:55 PM
Super User
Posts: 23,663

Re: Unable to define Arrays in SAS University Edtion

[ Edited ]
Posted in reply to lglovenish96

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.

 

 

Occasional Contributor
Posts: 6

Re: Unable to define Arrays in SAS University Edtion

@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? 

Super User
Posts: 23,663

Re: Unable to define Arrays in SAS University Edtion

Posted in reply to lglovenish96

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? 


 

Occasional Contributor
Posts: 6

Re: Unable to define Arrays in SAS University Edtion

@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. Smiley Happy 

Super User
Posts: 23,663

Re: Unable to define Arrays in SAS University Edtion

Posted in reply to lglovenish96
You may want to look into the variable lists and shortcuts then instead.

http://documentation.sas.com/?docsetId=lrcon&docsetTarget=p0wphcpsfgx6o7n1sjtqzizp1n39.htm&docsetVer...
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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