|
|
|
||||
|
|
|||||
data test;
input a b;
datalines;
1 3
2 4
3 5
1 3
2 4
3 5
;
run;
%macro recode(myvar, num1, num2);
array &myvar._a(*) &myvar.&num1 - &myvar.&num2;
do i = &num1 to &num2;
&myvar._a(i - &num1 + 1 ) = .;
end;
do i = &num1 to &num2;
if (&myvar = i) then &myvar._a(i - &num1 + 1 ) = 1;
if (&myvar > .) and (&myvar ~= i) then &myvar._a(i - &num1 + 1) = 0;
end;
%mend;
options mprint mlogic;
data test2;
set test;
%recode(a, 1, 3);
%recode(b, 3, 5);
drop i;
run;
proc print data = test2;
run;
Obs a b a1 a2 a3 b3 b4 b5
1 1 3 1 0 0 1 0 0 2 2 4 0 1 0 0 1 0 3 3 5 0 0 1 0 0 1 4 1 3 1 0 0 1 0 0 5 2 4 0 1 0 0 1 0 6 3 5 0 0 1 0 0 1
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services