DATA Step, Macro, Functions and more

SAS arrays

Reply
New Contributor Acp
New Contributor
Posts: 2

SAS arrays

array salv(*) Performance_:;                                                                                                            
array delqnorm(26);                                                                                                                     
array maxdelqnorm(26);                                                                                                                  
format maxdelqfirst12m maxdelqever 1.;                                                                                                  
do i = 1 to 26;                                                                                                                         
  if not missing (delq(i)) then                                                                                                         
    do;                                                                                                                                 
      offset=i;                                                                                                                         
          i=26;                                                                                                                         
    end;                                                                                                                                
end; 

Hi im new to sas programming... I'd came out through this code on SAS arrays... can anybody explain me what does "Performance_:" in line 1st and "offset=i" is representing here?

Valued Guide
Posts: 797

Re: SAS arrays

[ Edited ]

There are many ways to generate lists of variables names for use in array, keep, drop and other statements.

 

The use of the right hand colon says to use all vars whose name begins with "performance_".

 

You could also use

 

   array x{*}   performance_1-performance_5;   /* single dash,which tells sas to look generate all vars performanc_1 performance_2 performance_3 performance_4 performance_5.*/

 

or a specific list:

   array x{*} performance_1 performance_2 performance_2 performance_4 performance_5;

 

or a double dash

   array x{*}    perform -- return ;   /* which says to  use all vars from perform through return  in the program data vector.*/

New Contributor Acp
New Contributor
Posts: 2

Re: SAS arrays

Thanks man for providing  such an easy solution.... and can you please tell what would be the use of "offset" in above program?

Valued Guide
Posts: 797

Re: SAS arrays

[ Edited ]

 

The expression DELQ{i} says to use the i'th element of the array named DELQ, where i ranges from 1 to 26 in the DO loop (so your array better have at least 26 elements).  These 26 values are examined, and OFFSET  will  end up as the index of the "most recent"  (i.e. the rightmost) element of the DELQ array that is non-missing.

Trusted Advisor
Posts: 1,392

Re: SAS arrays

Just to add to @mkeintz post, you have a sysntax error in your code:

 

in order to use delq(i)  you have to define array by:

array delq {26} delq_1 - delq_26;   /* or delq:  or xxx1-xxx26.  See @mkeintz post */

- delq is the array name, while

- delq1-delq26 are the variables making the array

 

Beyond, what did you mean by line:

array maxdelqnorm(26);

are there 26 max values ? what variables create the array called  maxdelqnorm?

Super User
Super User
Posts: 6,502

Re: SAS arrays

[ Edited ]

The statement 

 

offset=i;

Is just an assignment statement. So it sets the value of OFFSET to the current value of I.

The purspose seems to store the index into the array of the first non-missing element in the array.  So the offset from the begginnig of the list.

So if you array had the series of values : 

. . . . 15 23 7 .

Then OFFSET would get set to 5 since the first non-missing value is the 15 in the fifth position.

The statement

I=26;

Is intended to cause the DO loop to end.

You could re-write it like this and it might be a little clearer.

offset=.;
do i=1 to dim(delq) while (offset=.);
  if not missing(delq(i)) then offset=i;
end;

 Also make sure the name you use in the ARRAY statement matches the name you are using in your array references. This loop is referencing the array named DELQ, but you did not include an ARRAY statement to define that array in the code you posted.

Ask a Question
Discussion stats
  • 5 replies
  • 155 views
  • 0 likes
  • 4 in conversation