Dick Duck's SAS tips

This is the nest where I keep my SAS eggs. It's all here... Arrays, control loops, links to online SAS resources, you name it.

Monday, February 20, 2006

Converting a variable from numeric to character

Earlier, we 'converted' a variable from character to numeric. Sometimes, we want to go the other way. Here is how:

data s1b (drop = i n5 n7 n10 n19 n21 n22 n36); 
set s1 (rename=(q5=n5 q7=n7 q10=n10 q19=n19 q21=n21 q22=n22 q36=n36));
array qq $ q5 q7 q10 q19 q21 q22 q36;
array nn n5 n7 n10 n19 n21 n22 n36;
do i = 1 to dim(qq);
qq[i] = put (nn[i], 8.0);
end;
run;
Instead of using 'input', we use 'put'. Also, this example uses arrays to convert multiple variables at the same time. If the items had been consecutive, we could have shortened the code by using ranges (q1-q5).

0 Comments:

Post a Comment

<< Home