Reordering variables
You've finally got your data the way you want them, but now they're in the wrong order. Let's say we have the answers to 62 multiple-choice questions, and we want them all nicely lined up. The trick is similar to char to num conversion:
data answers (drop = i t1-t62);We need to set the length attribute if we want the new variables to have the same length as the old ones.
set answers (rename=(q1-q62=t1-t62));
array qq1 $ t1-t62;
attrib q1-q62 length = $1;
array qq2 $ q1-q62;
do i = 1 to dim(qq1);
qq2[i] = qq1[i];
end;
run;
1 Comments:
You can also achieve the same re-ordering of the variables with shorter code, like this:
data answers;
      attrib q1-q62 length=$1;
      set answers;
run;
Note that the attrib statement must come BEFORE the set statement for the idea to work.
Post a Comment
<< Home