テーブル内のいくつかの条件を考慮して、すべてのレコードに個別のセル値を割り当てる必要があります。
画像では、column1= elig, column2=status, column3= type, column4 =metro, column5=quartile, column6=urb, column7=cell
. if then else に書き込んだ最初の 3 つの条件 (別のテーブルから取得したもの)。
しかし、変数 `quartile、urb、および type を使い始めると、私が書いたものよりも優れたコードが必要になります。
- Metro は 1 から 4 まで増加します。
- 四分位数は、1 つおきのレコードで増加します。
- グループとして変更を入力します。
最初のブロックtype = 1
の場合、2 番目のブロックのtype maybe be 4 or 5
場合 (必ずしもインクリメンタルである必要はありません)。次のタイプのグループはtype 7,8,9,10
.
すべてのレコードのセル値のみが変更されます。マクロ変数を代用して名前を短くし、入力を節約できることはわかっていますが、このコードをコンパクトで効率的にするにはどうすればよいでしょうか。
よろしくお願いします。
If elig=0 then cell=0;
else if elig =1 then
do;
if status in ('2','3') then cell=1;
else if ( status = ' ' and typec=25 ) then cell =2;
else if (status ='1','4','') and (quartile = . ) then cell=2;
end;
else if elig= '1' and type =1 and metro eq='1' then
do;
if quartile = 1 and urb in ('1','2') then cell =1111;
else if quartile = 1 and urb = '3' then cell =1112;
else if quartile = 2 and urb in ('1','2') then cell =1121;
else if quartile = 2 and urb = '3' then cell =1122;
else if quartile =3 and urb in ('1','2') then cell =1141;
else if quartile = 3 and urb = '3' then cell =1142;
else if quartile = 4 and urb in ('1','2') then cell =1121;
else if quartile = 4 and urb = '3' then cell =1172;
end;
/*here will be 3 more blocks of code for metro =2,3,4* /
/*note type changes value after metro cycles through 4 iterations*/
else if elig='1' and type =('4','5') and metro eq='1 then
do;
if quartile = 1 and urb in ('1','2') then cell =1211;
else if quartile = 1 and urb = '3' then cell =1212;
else if quartile = 2 and urb in ('1','2') then cell =1221;
else if quartile = 2 and urb = '3' then cell =1222;
else if quartile =3 and urb in ('1','2') then cell =1241;
else if quartile = 3 and urb = '3' then cell =1242;
else if quartile = 4 and urb in ('1','2') then cell =1271;
else if quartile = 4 and urb = '3' then cell =1272;
end;
/*3 more blocks of code for metro =2,3,4* /
/*then type changes and metro=1 and so on*/
else if elig='1' and type type =('7','8') and metro eq=1 then
do;
/*more code until my groups end* /
end;