data wk1;input a b c d;
cards;
1 3 5 7
2 4 6 8
;
run;
如何实现以下变化
假设有以上wk1数据组,4个变量想变成2个合成变量,如论谁和谁组合每个变量只能用一次。比方说用变量a和变量b做成一个合成变量e,e变量里面如下
if a=1 and b=3 then e=1;
else if a=1 and b=4 then e=2;
else if a=2 and b=3 then e=3;
else if a=2 and b=4 then e=4;
然后在用变量c和变量d 组成一个变量f
if c=5 and b=7 then f=1;
else if c=5 and b=8 then f=2;
else if c=6 and b=7 then f=3;
else if c=6 and b=8 then f=4;
这是一种情况,第二种情况我还可以 变量a和变量c组合 b和变量d组合
还有一种情况 变量a和变量d组合 b和变量c组合
虽然4个变量,两两组合成合成变量可以有3种变化,实际工作中变量达到20个左右,如何把它简易化哪,也就是让他自动生成3中变化哪?
为什么要这些组合哪,因为我想把合成变量代入logistic中。虽说logistic中可以有class a*b c*d这样的写法,但是原理是一样的。
请高人指教。