BookmarkSubscribeRSS Feed
Acp
Calcite | Level 5 Acp
Calcite | Level 5
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?

5 REPLIES 5
mkeintz
PROC Star

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.*/

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Acp
Calcite | Level 5 Acp
Calcite | Level 5

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

mkeintz
PROC Star

 

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Shmuel
Garnet | Level 18

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?

Tom
Super User Tom
Super User

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.

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
  • 772 views
  • 0 likes
  • 4 in conversation