Return to Archive

SAS Tip of the Month
November 2005

The DIM function returns the number of elements in an array. I find this particulary useful when I am filling a series of variables with a value based on a condition. The following example looks at the variables SEX, RACE and AGE and places a value of 999 in the variable if it is missing:

   array dmvars{3} sex race age;
   do i=1 to dim(dmvars);
      if missing(dmvars(i)) then dmvars(i)=999;

This is easier than writing:

   if missing(sex) then sex=999;
   if missing(race) then race=999;
   if missing(age) then age=999;

I hope you find this tip useful.

Updated November 1, 2005